17#ifndef A11_FLOW_OFFSETS_H_
18#define A11_FLOW_OFFSETS_H_
26#include <nlohmann/json_fwd.hpp>
45 [[nodiscard]]
const std::string&
Text()
const {
return text_; }
47 [[nodiscard]]
size_t LineCount()
const {
return line_starts_.size(); }
50 [[nodiscard]]
size_t Utf16Of(
size_t byte_offset)
const;
53 [[nodiscard]]
size_t ByteOf(
size_t utf16_offset)
const;
57 [[nodiscard]] std::pair<int, int>
PositionOf(
size_t byte_offset)
const;
66 [[nodiscard]] std::pair<size_t, size_t> Step(
size_t offset)
const;
68 [[nodiscard]]
size_t LineEnd(
size_t line)
const;
72 std::vector<size_t> line_starts_;
76 std::vector<size_t> line_utf16_starts_;
112void RebaseToUtf16(nlohmann::json& answer,
const TextIndex& index);
A document, and the offset arithmetic every editor protocol needs over it.
Definition offsets.h:40
size_t Utf16Of(size_t byte_offset) const
How many UTF-16 units of the document precede this byte offset.
Definition offsets.cc:69
const std::string & Text() const
Definition offsets.h:45
std::pair< int, int > PositionOf(size_t byte_offset) const
The LSP position – zero-based line, UTF-16 units into it – of a byte offset.
Definition offsets.cc:101
size_t ByteOfPosition(int line, int character) const
The byte offset of an LSP position, clamped into the document.
Definition offsets.cc:116
size_t LineCount() const
Definition offsets.h:47
size_t ByteOf(size_t utf16_offset) const
The byte offset that many UTF-16 units into the document.
Definition offsets.cc:86
std::optional< std::string > text
The text, where the value is a string literal or a name bound to one.
Definition discover.cc:612
Definition boundary.cc:32
OffsetBasis
Which basis the offsets in a request and its answer are counted in.
Definition offsets.h:80
@ kUtf16
UTF-16 code units from the start of the file: what a JVM or JavaScript editor host indexes its docume...
@ kBytes
Bytes from the start of the file: the language's own, and the default.
void RebaseToUtf16(nlohmann::json &answer, const TextIndex &index)
Rewrite every document offset in an answer from bytes into UTF-16 units.
Definition offsets.cc:150
std::string_view OffsetBasisName(OffsetBasis basis)
The name of a basis, for a message and for the JSON.
Definition offsets.cc:146
bool OffsetBasisFromName(std::string_view name, OffsetBasis &basis)
The basis a request named, or kBytes when it named none.
Definition offsets.cc:134
int line
Definition main.cc:70
long long offset
Definition main.cc:69