mirror of
https://github.com/helix-editor/helix
synced 2026-03-20 13:15:07 +01:00
This introduces another `Range` type which is an enum: either the
(character) indices in a rope or a wrapper around `lsp::Range` - the
positions in the document according to the position encoding.
Internally we always use character (typically) or byte indices into the
text to represent positions into the text. LSP however uses row and
column counts where the column meaning depends on the position encoding
negotiated with the server. This makes it difficult to have concepts
like `Diagnostic` be generic between an internal feature (for example
spell checking errors) and LSP. The solution here is direct: use an enum
that represents either format of describing a range of positions.
This change introduces that `Range` and uses it for two purposes:
* `Diagnostic` has been rewritten and moved from helix-core to
helix-view. The diagnostic type in `helix_view::document` is now a
wrapper around `helix_view::Diagnostic`, tracking the actual ranges
into the document.
* The `Location` type in `commands::lsp` has been refactored to use this
range instead of directly using `lsp::Range`.
The point of this is to support emitting features like diagnostics and
symbols using internal features like a spell checker and tree-sitter
(respectively). Now the spell checking integration can attach
diagnostics itself, roughly like so:
let provider = DiagnosticProvider::Spelling;
let diagnostics = /* find spelling mistakes */
.map(|(word, range)| {
helix_view::Diagnostic {
message: format!("Possible spelling mistake '{word}'"),
severity: Some(Severity::Hint),
range: helix_view::Range::Document(range),
provider: provider.clone(),
..Default::default()
}
})
.collect();
editor.handle_diagnostics(
provider,
uri,
Some(doc_version),
diagnostics,
);
In addition we can use this to build tree-sitter based symbol pickers
(also see <https://redirect.github.com/helix-editor/helix/pull/12275>).
|
||
|---|---|---|
| .. | ||
| src | ||
| Cargo.toml | ||