summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-12-29 22:22:47 +0100
committerGitHub <noreply@github.com>2022-12-29 22:22:47 +0100
commit218d7ab7780d5e44d3badd1102a65a1be2afd00a (patch)
tree5e51b4a3f37f17398fa6d94500ac53646561ba88
parentef5f8cd265b4bf161832ee23abfbe10605cf5b67 (diff)
fix(lsp): completions for private variables (#17220)
-rw-r--r--cli/lsp/tsc.rs4
-rw-r--r--cli/tests/lsp_tests.rs43
2 files changed, 45 insertions, 2 deletions
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index de34c7fa6..7145d00c2 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -2205,7 +2205,7 @@ impl CompletionEntry {
return Some(insert_text.clone());
}
} else {
- return Some(self.name.replace('#', ""));
+ return None;
}
}
@@ -4060,7 +4060,7 @@ mod tests {
..Default::default()
};
let actual = fixture.get_filter_text();
- assert_eq!(actual, Some("abc".to_string()));
+ assert_eq!(actual, None);
let fixture = CompletionEntry {
kind: ScriptElementKind::MemberVariableElement,
diff --git a/cli/tests/lsp_tests.rs b/cli/tests/lsp_tests.rs
index 1236b6c45..48f354248 100644
--- a/cli/tests/lsp_tests.rs
+++ b/cli/tests/lsp_tests.rs
@@ -3739,6 +3739,49 @@ export class DuckConfig {
}
#[test]
+ fn lsp_completions_private_fields() {
+ let mut client = init("initialize_params.json");
+ did_open(
+ &mut client,
+ json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts",
+ "languageId": "typescript",
+ "version": 1,
+ "text": r#"class Foo { #myProperty = "value"; constructor() { this.# } }"#
+ }
+ }),
+ );
+ let (maybe_res, maybe_err) = client
+ .write_request(
+ "textDocument/completion",
+ json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts"
+ },
+ "position": {
+ "line": 0,
+ "character": 57
+ },
+ "context": {
+ "triggerKind": 1
+ }
+ }),
+ )
+ .unwrap();
+ assert!(maybe_err.is_none());
+ if let Some(lsp::CompletionResponse::List(list)) = maybe_res {
+ assert_eq!(list.items.len(), 1);
+ let item = &list.items[0];
+ assert_eq!(item.label, "#myProperty");
+ assert!(!list.is_incomplete);
+ } else {
+ panic!("unexpected response");
+ }
+ shutdown(&mut client);
+ }
+
+ #[test]
fn lsp_completions_optional() {
let mut client = init("initialize_params.json");
did_open(