From cf6ec12afb65d9b31cdc13ffddb9750abe23a193 Mon Sep 17 00:00:00 2001 From: ef3d0c3e Date: Tue, 19 Nov 2024 09:51:24 +0100 Subject: [PATCH] Fix inlay hints not resolving correct position --- src/elements/script.rs | 5 +++-- src/lsp/hints.rs | 2 ++ src/lsp/semantic.rs | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/elements/script.rs b/src/elements/script.rs index c1a4367..a7989f6 100644 --- a/src/elements/script.rs +++ b/src/elements/script.rs @@ -271,7 +271,7 @@ impl RegexRule for ScriptRule { let range = matches .get(0) .map(|m| { - if token.source().content().as_bytes()[m.start()] == b'\n' { + if index == 0 && token.source().content().as_bytes()[m.start()] == b'\n' { m.start() + 1..m.end() } else { m.range() @@ -295,6 +295,7 @@ impl RegexRule for ScriptRule { } sems.add(matches.get(3).unwrap().range(), tokens.script_content); } + eprintln!("range={:#?}", range); sems.add(range.end - 2..range.end, tokens.script_sep); } @@ -306,7 +307,7 @@ impl RegexRule for ScriptRule { }); if !label.is_empty() { label.pop(); - hints.add(matches.get(0).unwrap().end(), label); + hints.add(matches.get(0).unwrap().end() - 1, label); } } diff --git a/src/lsp/hints.rs b/src/lsp/hints.rs index 9f7c4be..0ce3e9e 100644 --- a/src/lsp/hints.rs +++ b/src/lsp/hints.rs @@ -7,6 +7,7 @@ use tower_lsp::lsp_types::InlayHint; use crate::parser::source::LineCursor; use crate::parser::source::Source; use crate::parser::source::SourceFile; +use crate::parser::source::SourcePosition; use crate::parser::source::VirtualSource; use super::data::LSPData; @@ -82,6 +83,7 @@ impl<'a> Hints<'a> { } pub fn add(&self, position: usize, label: String) { + let position = self.original_source.original_position(position).1; let mut cursor = self.hints.cursor.borrow_mut(); cursor.move_to(position); diff --git a/src/lsp/semantic.rs b/src/lsp/semantic.rs index 82ffad6..22fcebb 100644 --- a/src/lsp/semantic.rs +++ b/src/lsp/semantic.rs @@ -435,6 +435,10 @@ impl<'a> Semantics<'a> { /// Add a semantic token to be processed instantly pub fn add(&self, range: Range, token: (u32, u32)) { let range = self.original_source.original_range(range).1; + eprintln!( + "Added {token:#?} range={range:#?} source={:#?}", + self.original_source + ); self.process_queue(range.start); self.add_impl(range, token); }