Skip to content

Commit

Permalink
fix(typescript): avoid duplicate completion items in plugin mode
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Sep 14, 2024
1 parent e864408 commit c8e6be1
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/typescript/lib/node/proxyLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,14 @@ function getCompletionsAtPosition(language: Language<string>, getCompletionsAtPo
return undefined;
}
if (serviceScript) {
const results: ts.CompletionInfo[] = [];
let mainResult: ts.CompletionInfo | undefined;
const additionalResults: ts.CompletionInfo[] = [];

for (const [generatedOffset, mapping] of toGeneratedOffsets(language, serviceScript, sourceScript, position, isCompletionEnabled)) {
const isAdditional = typeof mapping.data.completion === 'object' && mapping.data.completion.isAdditional;
if (!isAdditional && mainResult?.entries.length) {
continue;
}
const result = getCompletionsAtPosition(targetScript.id, generatedOffset, options, formattingSettings);
if (!result) {
continue;
Expand All @@ -875,14 +881,17 @@ function getCompletionsAtPosition(language: Language<string>, getCompletionsAtPo
}
result.optionalReplacementSpan = result.optionalReplacementSpan
&& transformTextSpan(sourceScript, language, serviceScript, result.optionalReplacementSpan, isCompletionEnabled)?.[1];
const isAdditional = typeof mapping.data.completion === 'object' && mapping.data.completion.isAdditional;
if (isAdditional) {
results.push(result);
additionalResults.push(result);
}
else {
results.unshift(result);
mainResult = result;
}
}
const results = additionalResults;
if (mainResult) {
results.unshift(mainResult);
}
if (results.length) {
return {
...results[0],
Expand Down Expand Up @@ -952,8 +961,8 @@ function provideInlayHints(language: Language<string>, provideInlayHints: ts.Lan
&& mapping.sourceOffsets.length == 1
&& (!mapping.generatedLengths || mapping.generatedLengths[0] === mapping.lengths[0])
) {
genStart = mapping.generatedOffsets[0] + span.start - mappingStart
genEnd = Math.min(genStart + span.length, mapping.generatedOffsets[0] + mapping.lengths[0])
genStart = mapping.generatedOffsets[0] + span.start - mappingStart;
genEnd = Math.min(genStart + span.length, mapping.generatedOffsets[0] + mapping.lengths[0]);
} else {
continue;
}
Expand Down

0 comments on commit c8e6be1

Please sign in to comment.