mirror of
https://github.com/nushell/nushell.git
synced 2025-05-31 15:18:23 +02:00
fix: module record variable
This commit is contained in:
parent
b7ea923f36
commit
aff75c7d93
@ -159,7 +159,16 @@ fn try_find_id_in_use(
|
|||||||
Some(Id::Variable(var_id_ref)) => module
|
Some(Id::Variable(var_id_ref)) => module
|
||||||
.constants
|
.constants
|
||||||
.get(name)
|
.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| {
|
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))
|
(*decl_id == *decl_id_ref).then_some(Id::Declaration(*decl_id))
|
||||||
}),
|
}),
|
||||||
|
@ -1130,7 +1130,6 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: associate the module record with the submodule name in `use`?
|
|
||||||
#[test]
|
#[test]
|
||||||
fn document_highlight_module_record() {
|
fn document_highlight_module_record() {
|
||||||
let mut script = fixtures();
|
let mut script = fixtures();
|
||||||
@ -1149,6 +1148,7 @@ mod tests {
|
|||||||
assert_json_eq!(
|
assert_json_eq!(
|
||||||
r.result,
|
r.result,
|
||||||
serde_json::json!([
|
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 },
|
{ "range": { "start": { "line": 8, "character": 1 }, "end": { "line": 8, "character": 8 } }, "kind": 1 },
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user