Add config file diag related types to protocol
This commit is contained in:
parent
c14362e2ae
commit
5da620efe4
3 changed files with 111 additions and 62 deletions
|
@ -1096,12 +1096,12 @@ namespace ts.server {
|
|||
* @param filename is absolute pathname
|
||||
* @param fileContent is a known version of the file content that is more up to date than the one on disk
|
||||
*/
|
||||
openClientFile(fileName: string, fileContent?: string, scriptKind?: ScriptKind): { info: ScriptInfo, configFileName?: string, configFileErrors?: Diagnostic[] } {
|
||||
openClientFile(fileName: string, fileContent?: string, scriptKind?: ScriptKind): { configFileName?: string, configFileErrors?: Diagnostic[] } {
|
||||
const { configFileName, configFileErrors } = this.openOrUpdateConfiguredProjectForFile(fileName);
|
||||
const info = this.openFile(fileName, /*openedByClient*/ true, fileContent, scriptKind);
|
||||
this.addOpenFile(info);
|
||||
this.printProjects();
|
||||
return { info, configFileName, configFileErrors };
|
||||
return { configFileName, configFileErrors };
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
26
src/server/protocol.d.ts
vendored
26
src/server/protocol.d.ts
vendored
|
@ -1010,6 +1010,32 @@ declare namespace ts.server.protocol {
|
|||
body?: DiagnosticEventBody;
|
||||
}
|
||||
|
||||
export interface ConfigFileDiagnosticEventBody {
|
||||
/**
|
||||
* The file which trigged the searching and error-checking of the config file
|
||||
*/
|
||||
triggerFile: string;
|
||||
|
||||
/**
|
||||
* The name of the found config file.
|
||||
*/
|
||||
configFile: string;
|
||||
|
||||
/**
|
||||
* An arry of diagnostic information items for the found config file.
|
||||
*/
|
||||
diagnostics: Diagnostic[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Event message for "configFileDiag" event type.
|
||||
* This event provides errors for a found config file.
|
||||
*/
|
||||
export interface ConfigFileDiagnosticEvent extends Event {
|
||||
body?: ConfigFileDiagnosticEventBody;
|
||||
event: "configFileDiag";
|
||||
}
|
||||
|
||||
/**
|
||||
* Arguments for reload request.
|
||||
*/
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace ts.server {
|
|||
}
|
||||
}
|
||||
|
||||
function formatDiag(fileName: string, project: Project, diag: ts.Diagnostic) {
|
||||
function formatDiag(fileName: string, project: Project, diag: ts.Diagnostic): protocol.Diagnostic {
|
||||
return {
|
||||
start: project.compilerService.host.positionToLineOffset(fileName, diag.start),
|
||||
end: project.compilerService.host.positionToLineOffset(fileName, diag.start + diag.length),
|
||||
|
@ -76,6 +76,14 @@ namespace ts.server {
|
|||
};
|
||||
}
|
||||
|
||||
function formatConfigFileDiag(diag: ts.Diagnostic): protocol.Diagnostic {
|
||||
return {
|
||||
start: undefined,
|
||||
end: undefined,
|
||||
text: ts.flattenDiagnosticMessageText(diag.messageText, "\n")
|
||||
};
|
||||
}
|
||||
|
||||
export interface PendingErrorCheck {
|
||||
fileName: string;
|
||||
project: Project;
|
||||
|
@ -178,6 +186,21 @@ namespace ts.server {
|
|||
"\r\n\r\n" + json);
|
||||
}
|
||||
|
||||
public configFileDiagnosticEvent(triggerFile: string, configFile: string, diagnostics: ts.Diagnostic[]) {
|
||||
const bakedDiags = ts.map(diagnostics, formatConfigFileDiag);
|
||||
const ev: protocol.ConfigFileDiagnosticEvent = {
|
||||
seq: 0,
|
||||
type: "event",
|
||||
event: "configFileDiag",
|
||||
body: {
|
||||
triggerFile,
|
||||
configFile,
|
||||
diagnostics: bakedDiags
|
||||
}
|
||||
};
|
||||
this.send(ev);
|
||||
}
|
||||
|
||||
public event(info: any, eventName: string) {
|
||||
const ev: protocol.Event = {
|
||||
seq: 0,
|
||||
|
@ -561,9 +584,9 @@ namespace ts.server {
|
|||
*/
|
||||
private openClientFile(fileName: string, fileContent?: string, scriptKind?: ScriptKind) {
|
||||
const file = ts.normalizePath(fileName);
|
||||
const { info, configFileName, configFileErrors } = this.projectService.openClientFile(file, fileContent, scriptKind);
|
||||
const { configFileName, configFileErrors } = this.projectService.openClientFile(file, fileContent, scriptKind);
|
||||
if (configFileErrors) {
|
||||
this.event({ triggerFile: fileName, configFile: configFileName, diagnostics: configFileErrors }, "configFileDiag");
|
||||
this.configFileDiagnosticEvent(fileName, configFileName, configFileErrors);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue