Skip to content

Commit

Permalink
fix: prevent false-positive auto completions on Svelte components (#2564
Browse files Browse the repository at this point in the history
)

Because Svelte components take precedence, we leave out commit characters to not auto complete in weird places (e.g. when you have `foo.filter(a => a)`) and get autocomplete for component A, then a commit character of `.` would auto import the component which is not what we want

Found after merging #2545 and playing around with it a bit
  • Loading branch information
dummdidumm authored Nov 5, 2024
1 parent b823694 commit 02b6b06
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ export class CompletionsProviderImpl implements CompletionsProvider<CompletionRe
label,
insertText,
kind: scriptElementKindToCompletionItemKind(comp.kind),
commitCharacters: this.getCommitCharacters(comp, commitCharactersOptions),
commitCharacters: this.getCommitCharacters(comp, commitCharactersOptions, isSvelteComp),
// Make sure svelte component and runes take precedence
sortText: isRunesCompletion || isSvelteComp ? '-1' : comp.sortText,
preselect: isRunesCompletion || isSvelteComp ? true : comp.isRecommended,
Expand Down Expand Up @@ -791,7 +791,18 @@ export class CompletionsProviderImpl implements CompletionsProvider<CompletionRe
};
}

private getCommitCharacters(entry: ts.CompletionEntry, options: CommitCharactersOptions) {
private getCommitCharacters(
entry: ts.CompletionEntry,
options: CommitCharactersOptions,
isSvelteComp: boolean
) {
// Because Svelte components take precedence, we leave out commit characters to not auto complete
// in weird places (e.g. when you have foo.filter(a => a)) and get autocomplete for component A,
// then a commit character of `.` would auto import the component which is not what we want
if (isSvelteComp) {
return ['>'];
}

// https://github.com/microsoft/vscode/blob/d012408e88ffabd6456c367df4d343654da2eb10/extensions/typescript-language-features/src/languageFeatures/completions.ts#L504
if (!options.checkCommitCharacters) {
return undefined;
Expand Down

0 comments on commit 02b6b06

Please sign in to comment.