From 5a8eb62e4e803a90938e852228c9a9f64683d447 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 25 Apr 2024 13:00:17 -0700 Subject: [PATCH 1/2] Call clearFiles on internal EmitOutput diagnostics --- src/language/typescript/monaco.contribution.ts | 3 ++- src/language/typescript/tsWorker.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/language/typescript/monaco.contribution.ts b/src/language/typescript/monaco.contribution.ts index 4220bcfb..d0189021 100644 --- a/src/language/typescript/monaco.contribution.ts +++ b/src/language/typescript/monaco.contribution.ts @@ -216,9 +216,10 @@ export interface DiagnosticRelatedInformation { messageText: string | DiagnosticMessageChain; } -interface EmitOutput { +export interface EmitOutput { outputFiles: OutputFile[]; emitSkipped: boolean; + diagnostics?: Diagnostic[]; } interface OutputFile { name: string; diff --git a/src/language/typescript/tsWorker.ts b/src/language/typescript/tsWorker.ts index a0c7719e..4ffc8867 100644 --- a/src/language/typescript/tsWorker.ts +++ b/src/language/typescript/tsWorker.ts @@ -8,6 +8,7 @@ import { libFileMap } from './lib/lib'; import { Diagnostic, DiagnosticRelatedInformation, + EmitOutput, IExtraLibs, TypeScriptWorker as ITypeScriptWorker } from './monaco.contribution'; @@ -401,11 +402,18 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork return this._languageService.getRenameInfo(fileName, position, options); } - async getEmitOutput(fileName: string): Promise { + async getEmitOutput(fileName: string): Promise { if (fileNameIsLib(fileName)) { return { outputFiles: [], emitSkipped: true }; } - return this._languageService.getEmitOutput(fileName); + // The diagnostics property is internal, returning it without clearing breaks message serialization. + const emitOutput = this._languageService.getEmitOutput(fileName) as ts.EmitOutput & { + diagnostics?: ts.Diagnostic[]; + }; + const diagnostics = emitOutput.diagnostics + ? TypeScriptWorker.clearFiles(emitOutput.diagnostics) + : undefined; + return { ...emitOutput, diagnostics }; } async getCodeFixesAtPosition( From 7be409ee9899baa2ae797e9430c7a4242b7297e9 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 25 Apr 2024 13:56:35 -0700 Subject: [PATCH 2/2] Pass args down too --- src/language/typescript/monaco.contribution.ts | 6 +++++- src/language/typescript/tsWorker.ts | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/language/typescript/monaco.contribution.ts b/src/language/typescript/monaco.contribution.ts index d0189021..d272f375 100644 --- a/src/language/typescript/monaco.contribution.ts +++ b/src/language/typescript/monaco.contribution.ts @@ -522,7 +522,11 @@ export interface TypeScriptWorker { * Get transpiled output for the given file. * @returns `typescript.EmitOutput` */ - getEmitOutput(fileName: string): Promise; + getEmitOutput( + fileName: string, + emitOnlyDtsFiles?: boolean, + forceDtsEmit?: boolean + ): Promise; /** * Get possible code fixes at the given position in the file. diff --git a/src/language/typescript/tsWorker.ts b/src/language/typescript/tsWorker.ts index 4ffc8867..c4f7d3eb 100644 --- a/src/language/typescript/tsWorker.ts +++ b/src/language/typescript/tsWorker.ts @@ -402,12 +402,20 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork return this._languageService.getRenameInfo(fileName, position, options); } - async getEmitOutput(fileName: string): Promise { + async getEmitOutput( + fileName: string, + emitOnlyDtsFiles?: boolean, + forceDtsEmit?: boolean + ): Promise { if (fileNameIsLib(fileName)) { return { outputFiles: [], emitSkipped: true }; } // The diagnostics property is internal, returning it without clearing breaks message serialization. - const emitOutput = this._languageService.getEmitOutput(fileName) as ts.EmitOutput & { + const emitOutput = this._languageService.getEmitOutput( + fileName, + emitOnlyDtsFiles, + forceDtsEmit + ) as ts.EmitOutput & { diagnostics?: ts.Diagnostic[]; }; const diagnostics = emitOutput.diagnostics