fix(lsp): regression of semantic tokens of module-prefixed commands (#15603)

# Description

Fixes a regression caused by #15567, where I made the space detection in
command names switched from `get_span_content` to `get_decl().name()`,
which is slightly faster but it won't work in some cases:

e.g.
```nushell
use std/assert
assert equal
```

Reverted in this PR.

# User-Facing Changes

None

# Tests + Formatting

Refined

# After Submitting
This commit is contained in:
zc he 2025-04-19 19:02:49 +08:00 committed by GitHub
parent a2dc3e3b33
commit 24dba9dc53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 6 deletions

View File

@ -22,11 +22,12 @@ fn extract_semantic_tokens_from_expression(
) -> Vec<Span> { ) -> Vec<Span> {
match &expr.expr { match &expr.expr {
Expr::Call(call) => { Expr::Call(call) => {
let command_name = working_set.get_decl(call.decl_id).name(); let command_name = working_set.get_span_contents(call.head);
if command_name.contains(' ') // Exclude some keywords that are supposed to be already highlighted properly,
// Some keywords that are already highlighted properly, e.g. by tree-sitter-nu // e.g. by tree-sitter-nu
&& !command_name.starts_with("export") if command_name.contains(&b' ')
&& !command_name.starts_with("overlay") && !command_name.starts_with(b"export")
&& !command_name.starts_with(b"overlay")
{ {
vec![call.head] vec![call.head]
} else { } else {
@ -144,7 +145,8 @@ mod tests {
1, 2, 10, 0, 0, 1, 2, 10, 0, 0,
7, 15, 13, 0, 0, 7, 15, 13, 0, 0,
0, 20, 10, 0, 0, 0, 20, 10, 0, 0,
4, 0, 7, 0, 0 4, 0, 7, 0, 0,
5, 0, 12, 0, 0
]}) ]})
); );
} }

View File

@ -13,3 +13,6 @@ export def "foo bar" [] {
foo bar foo bar
overlay use foo overlay use foo
use std/assert
assert equal