fix: module record variable

This commit is contained in:
blindfs 2025-04-08 20:56:25 +08:00
parent b7ea923f36
commit aff75c7d93
2 changed files with 11 additions and 2 deletions

View File

@ -159,7 +159,16 @@ fn try_find_id_in_use(
Some(Id::Variable(var_id_ref)) => module
.constants
.get(name)
.and_then(|var_id| (*var_id == *var_id_ref).then_some(Id::Variable(*var_id))),
.cloned()
.or_else(|| {
// NOTE: for module record variable: https://www.nushell.sh/book/modules/using_modules.html#importing-constants
// the definition span is located at the head of the use command
let var_id = working_set.find_variable(name)?;
call.span()
.contains_span(working_set.get_variable(var_id).declaration_span)
.then_some(var_id)
})
.and_then(|var_id| (var_id == *var_id_ref).then_some(Id::Variable(var_id))),
Some(Id::Declaration(decl_id_ref)) => module.decls.get(name).and_then(|decl_id| {
(*decl_id == *decl_id_ref).then_some(Id::Declaration(*decl_id))
}),

View File

@ -1130,7 +1130,6 @@ mod tests {
);
}
/// TODO: associate the module record with the submodule name in `use`?
#[test]
fn document_highlight_module_record() {
let mut script = fixtures();
@ -1149,6 +1148,7 @@ mod tests {
assert_json_eq!(
r.result,
serde_json::json!([
{ "range": { "start": { "line": 6, "character": 26 }, "end": { "line": 6, "character": 33 } }, "kind": 1 },
{ "range": { "start": { "line": 8, "character": 1 }, "end": { "line": 8, "character": 8 } }, "kind": 1 },
]),
);