diff --git a/src/language/typescript/monaco.contribution.ts b/src/language/typescript/monaco.contribution.ts index 4220bcfb2e..d272f375fa 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; @@ -521,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 a0c7719e1e..c4f7d3eba0 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,26 @@ 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 }; } - return this._languageService.getEmitOutput(fileName); + // The diagnostics property is internal, returning it without clearing breaks message serialization. + const emitOutput = this._languageService.getEmitOutput( + fileName, + emitOnlyDtsFiles, + forceDtsEmit + ) as ts.EmitOutput & { + diagnostics?: ts.Diagnostic[]; + }; + const diagnostics = emitOutput.diagnostics + ? TypeScriptWorker.clearFiles(emitOutput.diagnostics) + : undefined; + return { ...emitOutput, diagnostics }; } async getCodeFixesAtPosition(