Skip to content

Commit 763ded4

Browse files
committed
fix(parser): span of keyword expression
1 parent 5ca4e90 commit 763ded4

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

crates/nu-lsp/src/ast.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,6 @@ fn find_id_in_expr(
444444
) -> Option<Vec<(Id, Span)>> {
445445
// skip the entire expression if the location is not in it
446446
if !expr.span.contains(*location) {
447-
// TODO: the span of Keyword does not include its subsidiary expression
448-
// resort to `expr_flat_map` if location found in its expr
449-
if let Expr::Keyword(kw) = &expr.expr {
450-
if kw.expr.span.contains(*location) {
451-
return None;
452-
}
453-
}
454447
return Some(Vec::new());
455448
}
456449
let span = expr.span;

crates/nu-lsp/src/goto.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,24 @@ mod tests {
475475
})
476476
);
477477

478+
let resp = send_goto_definition_request(&client_connection, script.clone(), 1, 25);
479+
let result = if let Message::Response(response) = resp {
480+
response.result
481+
} else {
482+
panic!()
483+
};
484+
485+
assert_json_include!(
486+
actual: result,
487+
expected: serde_json::json!({
488+
"uri": script.to_string().replace("use_module", "module"),
489+
"range": {
490+
"start": { "line": 0, "character": 0 },
491+
"end": { "line": 3 }
492+
}
493+
})
494+
);
495+
478496
let resp = send_goto_definition_request(&client_connection, script.clone(), 2, 30);
479497
let result = if let Message::Response(response) = resp {
480498
response.result

crates/nu-parser/src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ pub fn parse_multispan_value(
919919
Expression::new(
920920
working_set,
921921
Expr::Keyword(Box::new(keyword.clone())),
922-
arg_span,
922+
keyword.span.merge(keyword.expr.span),
923923
keyword.expr.ty,
924924
)
925925
}

0 commit comments

Comments
 (0)