Skip to content

Commit

Permalink
fix(typescript): only fill source text for tsc
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Apr 21, 2024
1 parent 85ac78d commit f0aad5d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions packages/typescript/lib/node/decorateLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/typescript/lib/node/decorateProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
9 changes: 5 additions & 4 deletions packages/typescript/lib/node/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export function transformCallHierarchyItem(language: Language, item: ts.CallHier
};
}

export function transformDiagnostic<T extends ts.Diagnostic>(language: Language, diagnostic: T): T | undefined {
export function transformDiagnostic<T extends ts.Diagnostic>(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);
}

Expand All @@ -35,7 +35,9 @@ export function transformDiagnostic<T extends ts.Diagnostic>(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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f0aad5d

Please sign in to comment.