diff --git a/crates/nu-lsp/src/symbols.rs b/crates/nu-lsp/src/symbols.rs index 7cec5b5756..8b76b96817 100644 --- a/crates/nu-lsp/src/symbols.rs +++ b/crates/nu-lsp/src/symbols.rs @@ -118,10 +118,6 @@ impl SymbolCache { } let range = span_to_range(&span, doc, doc_span.start); let name = doc.get_content(Some(range)); - // TODO: better way to filter closures with type any - if name.contains('\r') || name.contains('\n') || name.contains('{') { - return None; - } Some(Symbol { name: name.to_string(), kind: SymbolKind::VARIABLE, @@ -343,6 +339,29 @@ mod tests { .unwrap() } + #[test] + // for variable `$in/$it`, should not appear in symbols + fn document_symbol_special_variables() { + let (client_connection, _recv) = initialize_language_server(); + + let mut script = fixtures(); + script.push("lsp"); + script.push("symbols"); + script.push("span.nu"); + let script = path_to_uri(&script); + + open_unchecked(&client_connection, script.clone()); + + let resp = document_symbol_test(&client_connection, script.clone()); + let result = if let Message::Response(response) = resp { + response.result + } else { + panic!() + }; + + assert_json_eq!(result, serde_json::json!([])); + } + #[test] fn document_symbol_basic() { let (client_connection, _recv) = initialize_language_server(); diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 93c8cf4425..dd11edc974 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -3435,7 +3435,7 @@ pub fn parse_full_signature(working_set: &mut StateWorkingSet, spans: &[Span]) - } pub fn parse_row_condition(working_set: &mut StateWorkingSet, spans: &[Span]) -> Expression { - let var_id = working_set.add_variable(b"$it".to_vec(), Span::concat(spans), Type::Any, false); + let var_id = working_set.add_variable(b"$it".to_vec(), Span::unknown(), Type::Any, false); let expression = parse_math_expression(working_set, spans, Some(var_id)); let span = Span::concat(spans); @@ -6633,7 +6633,7 @@ fn wrap_expr_with_collect(working_set: &mut StateWorkingSet, expr: Expression) - // IN_VARIABLE_ID should get replaced with a unique variable, so that we don't have to // execute as a closure - let var_id = working_set.add_variable(b"$in".into(), expr.span, Type::Any, false); + let var_id = working_set.add_variable(b"$in".into(), Span::unknown(), Type::Any, false); let mut expr = expr.clone(); expr.replace_in_variable(working_set, var_id); diff --git a/tests/fixtures/lsp/symbols/span.nu b/tests/fixtures/lsp/symbols/span.nu new file mode 100644 index 0000000000..3da732c79a --- /dev/null +++ b/tests/fixtures/lsp/symbols/span.nu @@ -0,0 +1,3 @@ +ls | where name != foo +ls | each { $in } +ls | $in.name