Skip to content
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

fix: abstract classes appear are listed under new ... autocompletions #7112

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
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
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