Skip to content

Commit 1e99934

Browse files
jadestrongzhangyuqiang
and
zhangyuqiang
authored
fix(52270): update optionalReplacementSpan in continuePreviousIncompleteResponse (microsoft#52287)
Co-authored-by: zhangyuqiang <[email protected]>
1 parent 83069ef commit 1e99934

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/services/completions.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ export function getCompletionsAtPosition(
665665
const compilerOptions = program.getCompilerOptions();
666666
const incompleteCompletionsCache = preferences.allowIncompleteCompletions ? host.getIncompleteCompletionsCache?.() : undefined;
667667
if (incompleteCompletionsCache && completionKind === CompletionTriggerKind.TriggerForIncompleteCompletions && previousToken && isIdentifier(previousToken)) {
668-
const incompleteContinuation = continuePreviousIncompleteResponse(incompleteCompletionsCache, sourceFile, previousToken, program, host, preferences, cancellationToken);
668+
const incompleteContinuation = continuePreviousIncompleteResponse(incompleteCompletionsCache, sourceFile, previousToken, program, host, preferences, cancellationToken, position);
669669
if (incompleteContinuation) {
670670
return incompleteContinuation;
671671
}
@@ -749,10 +749,12 @@ function continuePreviousIncompleteResponse(
749749
host: LanguageServiceHost,
750750
preferences: UserPreferences,
751751
cancellationToken: CancellationToken,
752+
position: number,
752753
): CompletionInfo | undefined {
753754
const previousResponse = cache.get();
754755
if (!previousResponse) return undefined;
755756

757+
const touchNode = getTouchingPropertyName(file, position);
756758
const lowerCaseTokenText = location.text.toLowerCase();
757759
const exportMap = getExportInfoMap(file, host, program, preferences, cancellationToken);
758760
const newEntries = resolvingModuleSpecifiers(
@@ -808,6 +810,7 @@ function continuePreviousIncompleteResponse(
808810

809811
previousResponse.entries = newEntries;
810812
previousResponse.flags = (previousResponse.flags || 0) | CompletionInfoFlags.IsContinuation;
813+
previousResponse.optionalReplacementSpan = getOptionalReplacementSpan(touchNode);
811814
return previousResponse;
812815
}
813816

src/testRunner/unittests/tsserver/completionsIncomplete.ts

+2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ describe("unittests:: tsserver:: completionsIncomplete", () => {
6565
assert(completions.isIncomplete);
6666
assert.lengthOf(completions.entries.filter(entry => (entry.data as any)?.moduleSpecifier), ts.Completions.moduleSpecifierResolutionLimit);
6767
assert.lengthOf(completions.entries.filter(entry => entry.source && !(entry.data as any)?.moduleSpecifier), excessFileCount);
68+
assert.deepEqual(completions.optionalReplacementSpan, { start: { line: 1, offset: 1 }, end: { line: 1, offset: 2 } });
6869
})
6970
.continueTyping("a", completions => {
7071
assert(completions.isIncomplete);
7172
assert.lengthOf(completions.entries.filter(entry => (entry.data as any)?.moduleSpecifier), ts.Completions.moduleSpecifierResolutionLimit * 2);
73+
assert.deepEqual(completions.optionalReplacementSpan, { start: { line: 1, offset: 1 }, end: { line: 1, offset: 3 } });
7274
})
7375
.continueTyping("_", completions => {
7476
assert(!completions.isIncomplete);

0 commit comments

Comments
 (0)