Skip to content

Never flag _ as an unknown identifier #804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions crates/ark/src/lsp/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub(crate) fn generate_diagnostics(doc: Document, state: WorldState) -> Vec<Diag
_ => {},
});

// Add per-environment session symbols
for scope in state.console_scopes.iter() {
for name in scope.iter() {
if is_symbol_valid(name.as_str()) {
Expand All @@ -142,6 +143,10 @@ pub(crate) fn generate_diagnostics(doc: Document, state: WorldState) -> Vec<Diag
}
}

// Add `_` pipe placeholder as a "known" session symbol so we never flag it with
// "symbol not found" when it shows up as an `identifier` node
context.session_symbols.insert(String::from("_"));

for pkg in state.installed_packages.iter() {
context.installed_packages.insert(pkg.clone());
}
Expand Down Expand Up @@ -1423,4 +1428,43 @@ foo
);
})
}

#[test]
fn test_no_symbol_diagnostics_for_native_pipe_placeholder() {
r_task(|| {
// https://github.com/posit-dev/positron/issues/4102
let code = "
x <- list(a = 1)
x |> _$a[1]
";
let document = Document::new(code, None);
assert_eq!(
generate_diagnostics(document.clone(), DEFAULT_STATE.clone()).len(),
0
);

// Imagine this is a data.table
// https://github.com/posit-dev/positron/issues/3749
let code = "
data <- data.frame(a = 1)
data |> _[1]
";
let document = Document::new(code, None);
assert_eq!(
generate_diagnostics(document.clone(), DEFAULT_STATE.clone()).len(),
0
);

// We technically disable diagnostics for this symbol everywhere, even outside
// of pipe scope, which is probably fine
let code = "
_
";
let document = Document::new(code, None);
assert_eq!(
generate_diagnostics(document.clone(), DEFAULT_STATE.clone()).len(),
0
);
})
}
}