Closed schungx closed 1 year ago
We're looking at improper range values here.
pub fn covering_element(&self, range: TextRange) -> SyntaxElement {
let mut res: SyntaxElement = self.clone().into();
loop {
assert!(
res.text_range().contains_range(range),
"Bad range: node range {:?}, range {:?}",
res.text_range(),
range,
);
res = match &res {
NodeOrToken::Token(_) => return res,
NodeOrToken::Node(node) => match node.child_or_token_at_range(range) {
Some(it) => it,
None => return res,
},
};
}
}
The range (505..524
) seems to be the length of the exact variable definition statement inside a rhai-scope
code block, so I believe some offsets are screwed up...
OK, I found a pattern.
Seems like, for code inside a rhai-scope
block, each character advances the position by 4 instead of 1. Therefore, if a rhai-scope
block is long enough, it goes over the entire script's range.
Tried the latest version, but still getting range errors with rhai-scope
.
Yeah I haven't touched on this yet.
Do you happen to have an MCVE for this?
Of course, it happens every single time when I open the foo.rhai
file from examples
.
Vscode will try 5 times, then fail the extension.
Of course, I'm on Windows, so I suspect it is a Windows thing, otherwise you'd have caught it ages ago.
The pattern is counting character offsets which are multiplied four times. I delete one character, the incorrect range shrinks by 4 places, all the way until the rhai-scope
block is short enough (or the script is long enough) that the range no longer becomes an error. Then it works fine.
Seems to be a windows issue indeed, I do not account for CRLF somewhere, changing the file to LF makes the panics go away.
OK, changing that one file foo.rhai
to LF makes ALL the problems go away! Everything Just Works(TM).
This seems to have fixed, even with CRLF. Closing.
Failed to load. Error log attached.
lsp_log.txt
The error is raised in
collect_symbols
when collecting scope symbols.document_symbols.rs:79