prevent premature autocomplete on intellisense

suggestion

When editing JS files, typing "window." triggers intellisense and
automatically selects the first suggestion ("window.AbortController")
The AI model would then use this default selection to insert a
completion without user input.

This commit updates the logic so that AI autocompletion only triggers
once the user has typed a few characters beyond the default suggestion,
ensuring that unwanted completions are not inserted early.
This commit is contained in:
Keerthana Panyam 2025-03-11 15:12:56 -04:00
parent 09d7a1861e
commit 304056d499

View file

@ -121,17 +121,23 @@ export class ContinueCompletionProvider
return null;
}
// If the text at the range isn't a prefix of the intellisense text,
// no completion will be displayed, regardless of what we return
if (
context.selectedCompletionInfo &&
!context.selectedCompletionInfo.text.startsWith(
document.getText(context.selectedCompletionInfo.range),
)
) {
return null;
}
// This code checks if there is a selected completion suggestion in the given context and ensures that it is valid.
// To improve the accuracy of suggestions it checks if the user has typed at least 4 characters
// This helps refine and filter out irrelevant autocomplete options
if (context.selectedCompletionInfo) {
const { text, range } = context.selectedCompletionInfo;
const typedText = document.getText(range);
const typedLength = range.end.character - range.start.character;
if (typedLength < 4) {
return null;
}
if (!text.startsWith(typedText)) {
return null;
}
}
let injectDetails: string | undefined = undefined;
// The first time intellisense dropdown shows up, and the first choice is selected,