diff --git a/packages/typescript/lib/node/decorateLanguageService.ts b/packages/typescript/lib/node/decorateLanguageService.ts index 289efbdc..bb423810 100644 --- a/packages/typescript/lib/node/decorateLanguageService.ts +++ b/packages/typescript/lib/node/decorateLanguageService.ts @@ -458,17 +458,17 @@ export function decorateLanguageService(language: Language, languageService: ts. }; languageService.getSyntacticDiagnostics = fileName => { return getSyntacticDiagnostics(fileName) - .map(d => transformDiagnostic(language, d)) + .map(d => transformDiagnostic(language, d, false)) .filter(notEmpty); }; languageService.getSemanticDiagnostics = fileName => { return getSemanticDiagnostics(fileName) - .map(d => transformDiagnostic(language, d)) + .map(d => transformDiagnostic(language, d, false)) .filter(notEmpty); }; languageService.getSuggestionDiagnostics = fileName => { return getSuggestionDiagnostics(fileName) - .map(d => transformDiagnostic(language, d)) + .map(d => transformDiagnostic(language, d, false)) .filter(notEmpty); }; languageService.getDefinitionAndBoundSpan = (fileName, position) => { diff --git a/packages/typescript/lib/node/decorateProgram.ts b/packages/typescript/lib/node/decorateProgram.ts index d3d3eaa0..d7c303ec 100644 --- a/packages/typescript/lib/node/decorateProgram.ts +++ b/packages/typescript/lib/node/decorateProgram.ts @@ -22,29 +22,29 @@ export function decorateProgram(language: Language, program: ts.Program) { return { ...result, diagnostics: result.diagnostics - .map(d => transformDiagnostic(language, d)) + .map(d => transformDiagnostic(language, d, true)) .filter(notEmpty), }; }; program.getSyntacticDiagnostics = (sourceFile, cancellationToken) => { return getSyntacticDiagnostics(sourceFile, cancellationToken) - .map(d => transformDiagnostic(language, d)) + .map(d => transformDiagnostic(language, d, true)) .filter(notEmpty); }; program.getSemanticDiagnostics = (sourceFile, cancellationToken) => { return getSemanticDiagnostics(sourceFile, cancellationToken) - .map(d => transformDiagnostic(language, d)) + .map(d => transformDiagnostic(language, d, true)) .filter(notEmpty); }; program.getGlobalDiagnostics = cancellationToken => { return getGlobalDiagnostics(cancellationToken) - .map(d => transformDiagnostic(language, d)) + .map(d => transformDiagnostic(language, d, true)) .filter(notEmpty); }; // @ts-ignore program.getBindAndCheckDiagnostics = (sourceFile, cancellationToken) => { return (getBindAndCheckDiagnostics as typeof getSyntacticDiagnostics)(sourceFile, cancellationToken) - .map(d => transformDiagnostic(language, d)) + .map(d => transformDiagnostic(language, d, true)) .filter(notEmpty); }; diff --git a/packages/typescript/lib/node/transform.ts b/packages/typescript/lib/node/transform.ts index 514f69cc..4c2a13bb 100644 --- a/packages/typescript/lib/node/transform.ts +++ b/packages/typescript/lib/node/transform.ts @@ -15,14 +15,14 @@ export function transformCallHierarchyItem(language: Language, item: ts.CallHier }; } -export function transformDiagnostic(language: Language, diagnostic: T): T | undefined { +export function transformDiagnostic(language: Language, diagnostic: T, isTsc: boolean): T | undefined { if (!transformedDiagnostics.has(diagnostic)) { transformedDiagnostics.set(diagnostic, undefined); const { relatedInformation } = diagnostic; if (relatedInformation) { diagnostic.relatedInformation = relatedInformation - .map(d => transformDiagnostic(language, d)) + .map(d => transformDiagnostic(language, d, isTsc)) .filter(notEmpty); } @@ -35,7 +35,9 @@ export function transformDiagnostic(language: Language, if (serviceScript) { const sourceSpan = transformTextSpan(sourceScript, map, { start: diagnostic.start, length: diagnostic.length }, shouldReportDiagnostics); if (sourceSpan) { - fillSourceFileText(language, diagnostic.file); + if (isTsc) { + fillSourceFileText(language, diagnostic.file); + } transformedDiagnostics.set(diagnostic, { ...diagnostic, start: sourceSpan.start, @@ -65,7 +67,6 @@ export function fillSourceFileText(language: Language, sourceFile: ts.SourceFile sourceFile.text = sourceScript.snapshot.getText(0, sourceScript.snapshot.getLength()) + sourceFile.text.substring(sourceScript.snapshot.getLength()); } - return; } export function transformFileTextChanges(language: Language, changes: ts.FileTextChanges, filter: (data: CodeInformation) => boolean): ts.FileTextChanges | undefined {