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: Prevent excessive autocompletion in template JS files #490

Merged
merged 4 commits into from
Mar 16, 2022

Conversation

randi274
Copy link
Contributor

What does this PR do?

  • Addresses a recent issue where we were providing autocomplete for curly braces in JS files, when we really only wanted to do so in HTML. This caused annoying and unhelpful autocomplete due to them firing off every time a conditional statement or method was declared. This reverts the JS autocomplete to how it was previously with a bit more semantic method naming to make it clear what the trigger characters are doing.

What issues does this PR fix or reference?

VS Code #3902. @W-10832653@

We shouldn't be checking for curly braces yet in JS files, so this fix ignores them entirely until
we explictly want to check for something. Updated tests to explictly test JS files as well.

vscode #3902
@randi274 randi274 requested a review from a team as a code owner March 15, 2022 15:30
@@ -141,7 +141,7 @@ export default class Server {
if (await this.context.isLWCTemplate(doc)) {
this.auraDataProvider.activated = false; // provide completions for lwc components in an Aura template
this.lwcDataProvider.activated = true;
if (params.context?.triggerCharacter === '{') {
if (this.shouldProvideBindingsInHTML(params)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to better naming here and for the shouldCompleteJavascript below, but I definitely didn't think the previous statement was clear on why we were matching on specific characters.

},
context: {
triggerCharacter: '{',
triggerKind: 2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

total nit: do we have an enum for triggerKind?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this comes from the vscode-language-server-protocol, where it looks like CompletionTriggerKind is declared as a type. Not sure if we can/want to import that here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah gotcha..yeah looks like we can just import and use that type.
Screen Shot 2022-03-15 at 4 13 09 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool beans, just added!

isIncomplete: false,
items: customTags,
};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so previously we always returned here, but we only return when it passes shouldCompleteJavascript. Should we move the inner if into the above condition, or should we be returning with no results when no matching tag was found?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what you mean. I think an early empty return like what we have for the last else would be a good change here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

things that make you go hummmmmmmmm. How does undefined qualify as a CompletionList?
weird.

I did a little digging and think it's b/c CompletionList is a namespace and an interface (maybe). sometimes I wonder if the teams at microsoft talk to each other :). eh. def better thanks for the update.
Screen Shot 2022-03-15 at 4 53 13 PM

@randi274 randi274 requested a review from floralan March 15, 2022 17:49
Copy link
Contributor

@gbockus-sf gbockus-sf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good work 👍

@randi274 randi274 merged commit 332082d into main Mar 16, 2022
@randi274 randi274 deleted the randi/fix-curly-brace-in-js branch March 16, 2022 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants