diff --git a/extensions/vscode/src/autocomplete/completionProvider.ts b/extensions/vscode/src/autocomplete/completionProvider.ts index f74de8409..c6e0b22e9 100644 --- a/extensions/vscode/src/autocomplete/completionProvider.ts +++ b/extensions/vscode/src/autocomplete/completionProvider.ts @@ -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,