diff --git a/packages/typescript/lib/node/transform.ts b/packages/typescript/lib/node/transform.ts index 4d3ddf8a..bbed9f1f 100644 --- a/packages/typescript/lib/node/transform.ts +++ b/packages/typescript/lib/node/transform.ts @@ -3,6 +3,7 @@ import type * as ts from 'typescript'; import { getServiceScript, notEmpty } from './utils'; const transformedDiagnostics = new WeakMap(); +const transformedSourceFiles = new WeakMap(); export function transformCallHierarchyItem(language: Language, item: ts.CallHierarchyItem, filter: (data: CodeInformation) => boolean): ts.CallHierarchyItem { const span = transformSpan(language, item.file, item.span, filter); @@ -19,7 +20,6 @@ export function transformDiagnostic(language: Language, transformedDiagnostics.set(diagnostic, undefined); const { relatedInformation } = diagnostic; - if (relatedInformation) { diagnostic.relatedInformation = relatedInformation .map(d => transformDiagnostic(language, d)) @@ -39,6 +39,7 @@ export function transformDiagnostic(language: Language, ...diagnostic, start: sourceSpan.start, length: sourceSpan.length, + file: transformSourceFile(diagnostic.file, sourceScript.snapshot.getText(0, sourceScript.snapshot.getLength())), }); } } @@ -53,6 +54,16 @@ export function transformDiagnostic(language: Language, return transformedDiagnostics.get(diagnostic) as T | undefined; } +export function transformSourceFile(sourceFile: ts.SourceFile, sourceText: string): ts.SourceFile { + if (!transformedSourceFiles.has(sourceFile)) { + transformedSourceFiles.set(sourceFile, { + ...sourceFile, + text: sourceText, + }); + } + return transformedSourceFiles.get(sourceFile)!; +} + export function transformFileTextChanges(language: Language, changes: ts.FileTextChanges, filter: (data: CodeInformation) => boolean): ts.FileTextChanges | undefined { const [_, source] = getServiceScript(language, changes.fileName); if (source) {