Struct lsp_document::Pos [−][src]
Expand description
Native position inside a text document/string. Points to a valid position before the character inside a UTF8-encoded string.
Why use Pos
instead of raw usize
offset
This depends on the use-case. Often raw usize
or a newtype wrapper around
usize
is sufficient. However, raw byte offsets are not stable at all when a
text document changes.
Usually, a text document is an input to later stages of the pipelines. Let’s take a simple incremental pipeline:
text: string ->
symbols: Symbol { ..., start: usize, end: usize } ->
diagnostics: Diag { ..., start: usize, end: usize }
Now, any change to text
on line N will shift all start
and end
offsets,
which will invalidate all symbols and diagnostics following the change and
require recomputation.
However, if start
and end
are Pos
es then only the line where the
change was made is affected. Symbols and diagnostic for other lines won’t be
invalidated.
Fields
line: u32
0-indexed line inside the text document.
col: u32
0-indexed byte offset from the beginning of the. The offset is at a valid char boundary.
Implementations
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Pos
impl UnwindSafe for Pos
Blanket Implementations
Mutably borrows from an owned value. Read more