From 515ef17207878b78e4f5eda8bf710fa0aa1eae87 Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Sun, 26 Mar 2023 18:14:42 +0200 Subject: make diagnostics stick to word boundaries Diagnostics are currently extended if text is inserted at their end. This is desirable when inserting text after an identifier. For example consider: let foo = 2; --- unused variable Renaming the identifier should extend the diagnostic: let foobar = 2; ------ unused variable This is currently implemented in helix but as a consequence adding whitespaces or a type hint also extends the diagnostic: let foo = 2; -------- unused variable let foo: Bar = 2; -------- unused variable In these cases the diagnostic should remain unchanged: let foo = 2; --- unused variable let foo: Bar = 2; --- unused variable As a heuristic helix will now only extend diagnostics that end on a word char if new chars are appended to the word (so not for punctuation/ whitespace). The idea for this mapping was inspired for the word level tracking vscode uses for many positions. While VSCode doesn't currently update diagnostics after receiving publishDiagnostic it does use this system for inlay hints for example. Similarly, the new association mechanism implemented here can be used for word level tracking of inlay hints. A similar mapping function is implemented for word starts. Together these can be used to make a diagnostic stick to a word. If that word is removed that diagnostic is automatically removed too. This is the exact same behavior VSCode inlay hints eixibit. --- helix-core/src/diagnostic.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'helix-core/src/diagnostic.rs') diff --git a/helix-core/src/diagnostic.rs b/helix-core/src/diagnostic.rs index 0b75d2a5..52d77a9a 100644 --- a/helix-core/src/diagnostic.rs +++ b/helix-core/src/diagnostic.rs @@ -39,6 +39,10 @@ pub enum DiagnosticTag { #[derive(Debug, Clone)] pub struct Diagnostic { pub range: Range, + // whether this diagnostic ends at the end of(or inside) a word + pub ends_at_word: bool, + pub starts_at_word: bool, + pub zero_width: bool, pub line: usize, pub message: String, pub severity: Option, -- cgit v1.2.3-70-g09d2