Skip to content

Commit

Permalink
fix(vscode): missing completions for types (identifiers) (#5726)
Browse files Browse the repository at this point in the history
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)*.
  • Loading branch information
MarkMcCulloh authored Feb 19, 2024
1 parent f0ceed4 commit d4e159e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
27 changes: 27 additions & 0 deletions libs/wingc/src/lsp/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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#"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: libs/wingc/src/lsp/completions.rs
---
- label: cloud
kind: 9
documentation:
kind: markdown
value: "Module `cloud`"
sortText: kk|cloud

0 comments on commit d4e159e

Please sign in to comment.