Skip to content

Commit

Permalink
Merge pull request #4482 from jakebailey/emit-file-diagnostics
Browse files Browse the repository at this point in the history
Call clearFiles on internal EmitOutput diagnostics, pass args down
  • Loading branch information
hediet authored May 30, 2024
2 parents 045e29b + 7be409e commit c49fdf9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/language/typescript/monaco.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 18 additions & 2 deletions src/language/typescript/tsWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { libFileMap } from './lib/lib';
import {
Diagnostic,
DiagnosticRelatedInformation,
EmitOutput,
IExtraLibs,
TypeScriptWorker as ITypeScriptWorker
} from './monaco.contribution';
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit c49fdf9

Please sign in to comment.