Merge pull request #4482 from jakebailey/emit-file-diagnostics

Call clearFiles on internal EmitOutput diagnostics, pass args down
This commit is contained in:
Henning Dieterichs 2024-05-30 19:29:01 +02:00 committed by GitHub
commit c49fdf9f0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 4 deletions

View File

@ -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<EmitOutput>;
getEmitOutput(
fileName: string,
emitOnlyDtsFiles?: boolean,
forceDtsEmit?: boolean
): Promise<EmitOutput>;
/**
* Get possible code fixes at the given position in the file.

View File

@ -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<ts.EmitOutput> {
async getEmitOutput(
fileName: string,
emitOnlyDtsFiles?: boolean,
forceDtsEmit?: boolean
): Promise<EmitOutput> {
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(