Skip to content

Commit

Permalink
fix: abstract classes appear are listed under new ... autocompletio…
Browse files Browse the repository at this point in the history
…ns (#7112)

fixes #6971 
## Checklist

- [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [ ] Description explains motivation and solution
- [ ] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*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
tsuf239 authored Sep 11, 2024
1 parent fb736d5 commit dd45d4f
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/@winglang/wingc/src/lsp/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,11 @@ fn format_symbol_kind_as_completion(name: &str, symbol_kind: &SymbolKind) -> Opt
return None;
}

// skipping abstract classes- so they won't appear in completions
if is_abstract_class(symbol_kind) {
return None;
}

Some(match symbol_kind {
SymbolKind::Type(t) => CompletionItem {
label: name.to_string(),
Expand Down Expand Up @@ -1188,6 +1193,15 @@ fn should_exclude_symbol(symbol: &str) -> bool {
symbol == WINGSDK_STD_MODULE || symbol.starts_with(CLOSURE_CLASS_PREFIX) || symbol.starts_with(PARENT_THIS_NAME)
}

fn is_abstract_class(symbol_kind: &SymbolKind) -> bool {
if let Some(t) = symbol_kind.as_type() {
if let Some(c) = t.as_class() {
return c.is_abstract;
}
}
return false;
}

fn str_to_access_context(s: &str) -> ObjectAccessContext {
match s {
"this" => ObjectAccessContext::This,
Expand Down Expand Up @@ -2053,6 +2067,17 @@ let x: cloud.Buc
assert!(partial_type_reference_annotation.iter().any(|c| c.label == "Bucket"))
);

test_completion_list!(
hide_abstract_members,
r#"
bring ui;
let x = new ui.
//^
"#,
assert!(hide_abstract_members.iter().all(|c| c.label != "VisualComponent"))
);

test_completion_list!(
no_completion_wrong_builtin,
r#"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
source: packages/@winglang/wingc/src/lsp/completions.rs
---
- label: Button
kind: 7
documentation:
kind: markdown
value: "```wing\nclass Button extends VisualComponent {\n static isVisualComponent(...): bool;\n}\n```\n---\nA button can be used to perform an action.\n\n*@noinflight*"
sortText: gg|Button
insertText: Button($1)
insertTextFormat: 2
command:
title: triggerParameterHints
command: editor.action.triggerParameterHints
- label: Field
kind: 7
documentation:
kind: markdown
value: "```wing\nclass Field extends VisualComponent {\n static isVisualComponent(...): bool;\n}\n```\n---\nA field can be used to display a value.\n\n*@noinflight*"
sortText: gg|Field
insertText: Field($1)
insertTextFormat: 2
command:
title: triggerParameterHints
command: editor.action.triggerParameterHints
- label: FileBrowser
kind: 7
documentation:
kind: markdown
value: "```wing\nclass FileBrowser extends VisualComponent {\n static isVisualComponent(...): bool;\n}\n```\n---\nA file browser can be used to browse files.\n\n*@noinflight*"
sortText: gg|FileBrowser
insertText: FileBrowser($1)
insertTextFormat: 2
command:
title: triggerParameterHints
command: editor.action.triggerParameterHints
- label: HttpClient
kind: 7
documentation:
kind: markdown
value: "```wing\nclass HttpClient extends VisualComponent {\n static isVisualComponent(...): bool;\n}\n```\n---\nAn HttpClient can be used to make HTTP requests.\n\n*@noinflight*"
sortText: gg|HttpClient
insertText: HttpClient($1)
insertTextFormat: 2
command:
title: triggerParameterHints
command: editor.action.triggerParameterHints
- label: Section
kind: 7
documentation:
kind: markdown
value: "```wing\nclass Section extends VisualComponent {\n add(...): void;\n addButton(...): void;\n addField(...): void;\n static isVisualComponent(...): bool;\n}\n```\n---\nA section can be used to group other visual components.\n\n*@noinflight*"
sortText: gg|Section
insertText: Section($1)
insertTextFormat: 2
command:
title: triggerParameterHints
command: editor.action.triggerParameterHints
- label: Table
kind: 7
documentation:
kind: markdown
value: "```wing\nclass Table extends VisualComponent {\n static isVisualComponent(...): bool;\n}\n```\n---\nA table can be used to browse files.\n\n*@noinflight*"
sortText: gg|Table
insertText: Table($1)
insertTextFormat: 2
command:
title: triggerParameterHints
command: editor.action.triggerParameterHints
- label: ValueField
kind: 7
documentation:
kind: markdown
value: "```wing\nclass ValueField extends Field {\n static isVisualComponent(...): bool;\n}\n```\n---\nA value field can be used to display a string value.\n\n*@noinflight*"
sortText: gg|ValueField
insertText: ValueField($1)
insertTextFormat: 2
command:
title: triggerParameterHints
command: editor.action.triggerParameterHints

0 comments on commit dd45d4f

Please sign in to comment.