Skip to content

Commit

Permalink
fix(typescript): getCompletionEntryDetails position have not mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Dec 15, 2023
1 parent cd5a302 commit a0d9295
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/typescript/lib/node/decorateLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
FileProvider,
isCallHierarchyEnabled,
isCodeActionsEnabled,
isCodeLensEnabled,
isCompletionEnabled,
isDefinitionEnabled,
isHighlightEnabled,
Expand Down Expand Up @@ -547,12 +546,28 @@ export function decorateLanguageService(files: FileProvider, languageService: ts
}
};
languageService.getCompletionEntryDetails = (fileName, position, entryName, formatOptions, source, preferences, data) => {
const details = getCompletionEntryDetails(fileName, position, entryName, formatOptions, source, preferences, data);

let details: ts.CompletionEntryDetails | undefined;

const [virtualFile, sourceFile, map] = getVirtualFileAndMap(files, fileName);
if (virtualFile) {
for (const [generateOffset, mapping] of map.getGeneratedOffsets(position)) {
if (isCompletionEnabled(mapping.data)) {
details = getCompletionEntryDetails(fileName, generateOffset + sourceFile.snapshot.getLength(), entryName, formatOptions, source, preferences, data);
break;
}
}
}
else {
return getCompletionEntryDetails(fileName, position, entryName, formatOptions, source, preferences, data);
}

if (details?.codeActions) {
for (const codeAction of details.codeActions) {
codeAction.changes = codeAction.changes.map(edit => transformFileTextChanges(files, edit, isCodeLensEnabled)).filter(notEmpty);
codeAction.changes = codeAction.changes.map(edit => transformFileTextChanges(files, edit, isCompletionEnabled)).filter(notEmpty);
}
}

return details;
};
languageService.provideInlayHints = (fileName, span, preferences) => {
Expand Down

0 comments on commit a0d9295

Please sign in to comment.