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(completions): don't create snippet kind without completeFunctionCalls #595

Merged
merged 3 commits into from
Sep 28, 2022

Conversation

rchl
Copy link
Member

@rchl rchl commented Sep 26, 2022

Server was supposed to create snippet completions on "resolve" for method and function completion kinds when the completeFunctionCalls workspace settings was enabled.

The code that has created the snippet during "resolve" was checking before-mentioned option but the code that initially set the insertTextFormat to Snippet did not. That meant that with completeFunctionCalls disabled, the method and function completions were set to Snippet kind initially but without a chance of being changed to actual snippets during "resolve".

And for editors that can't use resolved values that meant that those would potentially receive completions with unescaped $ character in them while not actually being actual snippet.

@@ -254,6 +254,10 @@ export async function isValidFunctionCompletionContext(filepath: string, positio
}
}

function canCreateSnippetOfFunctionCall(kind: lsp.CompletionItemKind | undefined, options: WorkspaceConfigurationCompletionOptions): boolean {
return options.completeFunctionCalls === true && (kind === lsp.CompletionItemKind.Function || kind === lsp.CompletionItemKind.Method);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return options.completeFunctionCalls === true && (kind === lsp.CompletionItemKind.Function || kind === lsp.CompletionItemKind.Method);
return options.completeFunctionCalls && (kind === lsp.CompletionItemKind.Function || kind === lsp.CompletionItemKind.Method);

Copy link
Member Author

Choose a reason for hiding this comment

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

That would cause type error as options.completeFunctionCalls can be undefined and the function returns boolean.

Copy link
Contributor

@predragnikolic predragnikolic left a comment

Choose a reason for hiding this comment

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

I can confirm that previously when having:

class A{
	$hello() {}
}

let a = new A()

a.| // try to select $hello in the autcomplete popup will result in not inserting anything in the document. (tested in Sublime Text)

after this change, it results in a.$hello being inserted. (completions.completeFunctionCalls is false)

I also set completions.completeFunctionCalls to true and it behaves as described in the comment.

@rchl rchl changed the title fix(completions): don't use snippet kind unless completeFunctionCalls is set fix(completions): don't create snippet kind without completeFunctionCalls Sep 28, 2022
@rchl rchl merged commit 7f69c27 into master Sep 28, 2022
@rchl rchl deleted the fix/snippet-completions branch September 28, 2022 18:00
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.

None yet

2 participants