17#ifndef A11_FLOW_OFFSETS_H_
18#define A11_FLOW_OFFSETS_H_
26#include <absl/container/flat_hash_map.h>
27#include <nlohmann/json_fwd.hpp>
46 [[nodiscard]]
const std::string&
Text()
const {
return text_; }
48 [[nodiscard]]
size_t LineCount()
const {
return line_starts_.size(); }
51 [[nodiscard]]
size_t Utf16Of(
size_t byte_offset)
const;
54 [[nodiscard]]
size_t ByteOf(
size_t utf16_offset)
const;
58 [[nodiscard]] std::pair<int, int>
PositionOf(
size_t byte_offset)
const;
70 [[nodiscard]] std::pair<size_t, size_t>
Step(
size_t offset)
const;
72 [[nodiscard]]
size_t LineEnd(
size_t line)
const;
76 std::vector<size_t> line_starts_;
80 std::vector<size_t> line_utf16_starts_;
116void RebaseToUtf16(nlohmann::json& answer,
const TextIndex& index);
120 nlohmann::json& answer,
const TextIndex& index,
121 const absl::flat_hash_map<std::string, TextIndex>& documents);
A document, and the offset arithmetic every editor protocol needs over it.
Definition offsets.h:41
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:46
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:129
size_t LineCount() const
Definition offsets.h:48
size_t ByteOf(size_t utf16_offset) const
The byte offset that many UTF-16 units into the document.
Definition offsets.cc:86
size_t ByteOfSourcePosition(int line, int column) const
Byte offset of a one-based source line and code-point column.
Definition offsets.cc:116
std::optional< std::string > text
The text, where the value is a string literal or a name bound to one.
Definition discover.cc:596
Definition catalogue.cc:29
OffsetBasis
Which basis the offsets in a request and its answer are counted in.
Definition offsets.h:84
@ 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:163
std::string_view OffsetBasisName(OffsetBasis basis)
The name of a basis, for a message and for the JSON.
Definition offsets.cc:159
bool OffsetBasisFromName(std::string_view name, OffsetBasis &basis)
The basis a request named, or kBytes when it named none.
Definition offsets.cc:147
std::uint32_t offset
Definition runtime_streams.cc:36
One resolved statement.
Definition graph.h:238
int line
Definition main.cc:71
int column
Definition main.cc:72