From d4e159eceffb7ae870f750aa4bc9d50a173e05e0 Mon Sep 17 00:00:00 2001 From: Mark McCulloh Date: Mon, 19 Feb 2024 15:33:23 -0500 Subject: [PATCH] fix(vscode): missing completions for types (identifiers) (#5726) In parser contexts where we know something is a type but it has no `.`, completions were not working. This is for situations like the text following `new`, `impl`, `extends`. Once you start typing after that, no completions would be available. *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*. --- libs/wingc/src/lsp/completions.rs | 27 +++++++++++++++++++ .../new_expression_partial_namespace.snap | 10 +++++++ 2 files changed, 37 insertions(+) create mode 100644 libs/wingc/src/lsp/snapshots/completions/new_expression_partial_namespace.snap diff --git a/libs/wingc/src/lsp/completions.rs b/libs/wingc/src/lsp/completions.rs index 49dc439a515..f0fee36dbb9 100644 --- a/libs/wingc/src/lsp/completions.rs +++ b/libs/wingc/src/lsp/completions.rs @@ -363,6 +363,18 @@ pub fn on_completion(params: lsp_types::CompletionParams) -> CompletionResponse return filter_completions(completions); } + + if node_to_complete_kind == "type_identifier" { + // we're in an incomplete bare type (e.g. `new clou` or `extends clo`), + // we should attempt to use the text we have to match existing scope symbols + return filter_completions(get_current_scope_completions( + &types, + &scope_visitor, + &node_to_complete, + &preceding_text, + )); + } + return vec![]; } } else if matches!( @@ -1309,6 +1321,21 @@ new cloud. // assert!(new_expression_nested.iter().all(|item| item.detail.as_ref().unwrap().starts_with("preflight"))) ); + test_completion_list!( + new_expression_partial_namespace, + r#" +bring cloud; + +struct cloudy {} + +new clo + //^ +"#, + assert!(!new_expression_partial_namespace.is_empty()) + assert!(new_expression_partial_namespace.len() == 1) + assert!(new_expression_partial_namespace.get(0).unwrap().label == "cloud") + ); + test_completion_list!( static_method_call, r#" diff --git a/libs/wingc/src/lsp/snapshots/completions/new_expression_partial_namespace.snap b/libs/wingc/src/lsp/snapshots/completions/new_expression_partial_namespace.snap new file mode 100644 index 00000000000..bc37b6bf184 --- /dev/null +++ b/libs/wingc/src/lsp/snapshots/completions/new_expression_partial_namespace.snap @@ -0,0 +1,10 @@ +--- +source: libs/wingc/src/lsp/completions.rs +--- +- label: cloud + kind: 9 + documentation: + kind: markdown + value: "Module `cloud`" + sortText: kk|cloud +