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 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
|
* @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 { configFileName, configFileErrors } = this.openOrUpdateConfiguredProjectForFile(fileName);
|
||||||
const info = this.openFile(fileName, /*openedByClient*/ true, fileContent, scriptKind);
|
const info = this.openFile(fileName, /*openedByClient*/ true, fileContent, scriptKind);
|
||||||
this.addOpenFile(info);
|
this.addOpenFile(info);
|
||||||
this.printProjects();
|
this.printProjects();
|
||||||
return { info, configFileName, configFileErrors };
|
return { configFileName, configFileErrors };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
140
src/server/protocol.d.ts
vendored
140
src/server/protocol.d.ts
vendored
|
@ -1,54 +1,54 @@
|
||||||
/**
|
/**
|
||||||
* Declaration module describing the TypeScript Server protocol
|
* Declaration module describing the TypeScript Server protocol
|
||||||
*/
|
*/
|
||||||
declare namespace ts.server.protocol {
|
declare namespace ts.server.protocol {
|
||||||
/**
|
/**
|
||||||
* A TypeScript Server message
|
* A TypeScript Server message
|
||||||
*/
|
*/
|
||||||
export interface Message {
|
export interface Message {
|
||||||
/**
|
/**
|
||||||
* Sequence number of the message
|
* Sequence number of the message
|
||||||
*/
|
*/
|
||||||
seq: number;
|
seq: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One of "request", "response", or "event"
|
* One of "request", "response", or "event"
|
||||||
*/
|
*/
|
||||||
type: string;
|
type: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client-initiated request message
|
* Client-initiated request message
|
||||||
*/
|
*/
|
||||||
export interface Request extends Message {
|
export interface Request extends Message {
|
||||||
/**
|
/**
|
||||||
* The command to execute
|
* The command to execute
|
||||||
*/
|
*/
|
||||||
command: string;
|
command: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object containing arguments for the command
|
* Object containing arguments for the command
|
||||||
*/
|
*/
|
||||||
arguments?: any;
|
arguments?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request to reload the project structure for all the opened files
|
* Request to reload the project structure for all the opened files
|
||||||
*/
|
*/
|
||||||
export interface ReloadProjectsRequest extends Message {
|
export interface ReloadProjectsRequest extends Message {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server-initiated event message
|
* Server-initiated event message
|
||||||
*/
|
*/
|
||||||
export interface Event extends Message {
|
export interface Event extends Message {
|
||||||
/**
|
/**
|
||||||
* Name of event
|
* Name of event
|
||||||
*/
|
*/
|
||||||
event: string;
|
event: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event-specific information
|
* Event-specific information
|
||||||
*/
|
*/
|
||||||
body?: any;
|
body?: any;
|
||||||
}
|
}
|
||||||
|
@ -62,18 +62,18 @@ declare namespace ts.server.protocol {
|
||||||
*/
|
*/
|
||||||
request_seq: number;
|
request_seq: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Outcome of the request.
|
* Outcome of the request.
|
||||||
*/
|
*/
|
||||||
success: boolean;
|
success: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The command requested.
|
* The command requested.
|
||||||
*/
|
*/
|
||||||
command: string;
|
command: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains error message if success === false.
|
* Contains error message if success === false.
|
||||||
*/
|
*/
|
||||||
message?: string;
|
message?: string;
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ declare namespace ts.server.protocol {
|
||||||
body?: any;
|
body?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arguments for FileRequest messages.
|
* Arguments for FileRequest messages.
|
||||||
*/
|
*/
|
||||||
export interface FileRequestArgs {
|
export interface FileRequestArgs {
|
||||||
|
@ -93,7 +93,7 @@ declare namespace ts.server.protocol {
|
||||||
file: string;
|
file: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arguments for ProjectInfoRequest request.
|
* Arguments for ProjectInfoRequest request.
|
||||||
*/
|
*/
|
||||||
export interface ProjectInfoRequestArgs extends FileRequestArgs {
|
export interface ProjectInfoRequestArgs extends FileRequestArgs {
|
||||||
|
@ -110,7 +110,7 @@ declare namespace ts.server.protocol {
|
||||||
arguments: ProjectInfoRequestArgs;
|
arguments: ProjectInfoRequestArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response message body for "projectInfo" request
|
* Response message body for "projectInfo" request
|
||||||
*/
|
*/
|
||||||
export interface ProjectInfo {
|
export interface ProjectInfo {
|
||||||
|
@ -125,7 +125,7 @@ declare namespace ts.server.protocol {
|
||||||
fileNames?: string[];
|
fileNames?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response message for "projectInfo" request
|
* Response message for "projectInfo" request
|
||||||
*/
|
*/
|
||||||
export interface ProjectInfoResponse extends Response {
|
export interface ProjectInfoResponse extends Response {
|
||||||
|
@ -144,12 +144,12 @@ declare namespace ts.server.protocol {
|
||||||
* (file, line, character offset), where line and character offset are 1-based.
|
* (file, line, character offset), where line and character offset are 1-based.
|
||||||
*/
|
*/
|
||||||
export interface FileLocationRequestArgs extends FileRequestArgs {
|
export interface FileLocationRequestArgs extends FileRequestArgs {
|
||||||
/**
|
/**
|
||||||
* The line number for the request (1-based).
|
* The line number for the request (1-based).
|
||||||
*/
|
*/
|
||||||
line: number;
|
line: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The character offset (on the line) for the request (1-based).
|
* The character offset (on the line) for the request (1-based).
|
||||||
*/
|
*/
|
||||||
offset: number;
|
offset: number;
|
||||||
|
@ -216,7 +216,7 @@ declare namespace ts.server.protocol {
|
||||||
* Object found in response messages defining a span of text in a specific source file.
|
* Object found in response messages defining a span of text in a specific source file.
|
||||||
*/
|
*/
|
||||||
export interface FileSpan extends TextSpan {
|
export interface FileSpan extends TextSpan {
|
||||||
/**
|
/**
|
||||||
* File containing text span.
|
* File containing text span.
|
||||||
*/
|
*/
|
||||||
file: string;
|
file: string;
|
||||||
|
@ -300,14 +300,14 @@ declare namespace ts.server.protocol {
|
||||||
*/
|
*/
|
||||||
lineText: string;
|
lineText: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if reference is a write location, false otherwise.
|
* True if reference is a write location, false otherwise.
|
||||||
*/
|
*/
|
||||||
isWriteAccess: boolean;
|
isWriteAccess: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The body of a "references" response message.
|
* The body of a "references" response message.
|
||||||
*/
|
*/
|
||||||
export interface ReferencesResponseBody {
|
export interface ReferencesResponseBody {
|
||||||
/**
|
/**
|
||||||
|
@ -325,7 +325,7 @@ declare namespace ts.server.protocol {
|
||||||
*/
|
*/
|
||||||
symbolStartOffset: number;
|
symbolStartOffset: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The full display name of the symbol.
|
* The full display name of the symbol.
|
||||||
*/
|
*/
|
||||||
symbolDisplayString: string;
|
symbolDisplayString: string;
|
||||||
|
@ -355,7 +355,7 @@ declare namespace ts.server.protocol {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information about the item to be renamed.
|
* Information about the item to be renamed.
|
||||||
*/
|
*/
|
||||||
export interface RenameInfo {
|
export interface RenameInfo {
|
||||||
/**
|
/**
|
||||||
|
@ -373,7 +373,7 @@ declare namespace ts.server.protocol {
|
||||||
*/
|
*/
|
||||||
displayName: string;
|
displayName: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full display name of item to be renamed.
|
* Full display name of item to be renamed.
|
||||||
*/
|
*/
|
||||||
fullDisplayName: string;
|
fullDisplayName: string;
|
||||||
|
@ -383,7 +383,7 @@ declare namespace ts.server.protocol {
|
||||||
*/
|
*/
|
||||||
kind: string;
|
kind: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional modifiers for the kind (such as 'public').
|
* Optional modifiers for the kind (such as 'public').
|
||||||
*/
|
*/
|
||||||
kindModifiers: string;
|
kindModifiers: string;
|
||||||
|
@ -477,7 +477,7 @@ declare namespace ts.server.protocol {
|
||||||
*/
|
*/
|
||||||
export interface ConfigureRequestArguments {
|
export interface ConfigureRequestArguments {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information about the host, for example 'Emacs 24.4' or
|
* Information about the host, for example 'Emacs 24.4' or
|
||||||
* 'Sublime Text version 3075'
|
* 'Sublime Text version 3075'
|
||||||
*/
|
*/
|
||||||
|
@ -495,7 +495,7 @@ declare namespace ts.server.protocol {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure request; value of command field is "configure". Specifies
|
* Configure request; value of command field is "configure". Specifies
|
||||||
* host information, such as host type, tab size, and indent size.
|
* host information, such as host type, tab size, and indent size.
|
||||||
*/
|
*/
|
||||||
export interface ConfigureRequest extends Request {
|
export interface ConfigureRequest extends Request {
|
||||||
|
@ -514,8 +514,8 @@ declare namespace ts.server.protocol {
|
||||||
*/
|
*/
|
||||||
export interface OpenRequestArgs extends FileRequestArgs {
|
export interface OpenRequestArgs extends FileRequestArgs {
|
||||||
/**
|
/**
|
||||||
* Used when a version of the file content is known to be more up to date than the one on disk.
|
* Used when a version of the file content is known to be more up to date than the one on disk.
|
||||||
* Then the known content will be used upon opening instead of the disk copy
|
* Then the known content will be used upon opening instead of the disk copy
|
||||||
*/
|
*/
|
||||||
fileContent?: string;
|
fileContent?: string;
|
||||||
/**
|
/**
|
||||||
|
@ -756,7 +756,7 @@ declare namespace ts.server.protocol {
|
||||||
* Optional modifiers for the kind (such as 'public').
|
* Optional modifiers for the kind (such as 'public').
|
||||||
*/
|
*/
|
||||||
kindModifiers: string;
|
kindModifiers: string;
|
||||||
/**
|
/**
|
||||||
* A string that is used for comparing completion items so that they can be ordered. This
|
* A string that is used for comparing completion items so that they can be ordered. This
|
||||||
* is often the same as the name but may be different in certain circumstances.
|
* is often the same as the name but may be different in certain circumstances.
|
||||||
*/
|
*/
|
||||||
|
@ -799,7 +799,7 @@ declare namespace ts.server.protocol {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signature help information for a single parameter
|
* Signature help information for a single parameter
|
||||||
*/
|
*/
|
||||||
export interface SignatureHelpParameter {
|
export interface SignatureHelpParameter {
|
||||||
|
|
||||||
|
@ -819,18 +819,18 @@ declare namespace ts.server.protocol {
|
||||||
displayParts: SymbolDisplayPart[];
|
displayParts: SymbolDisplayPart[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the parameter is optional or not.
|
* Whether the parameter is optional or not.
|
||||||
*/
|
*/
|
||||||
isOptional: boolean;
|
isOptional: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a single signature to show in signature help.
|
* Represents a single signature to show in signature help.
|
||||||
*/
|
*/
|
||||||
export interface SignatureHelpItem {
|
export interface SignatureHelpItem {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the signature accepts a variable number of arguments.
|
* Whether the signature accepts a variable number of arguments.
|
||||||
*/
|
*/
|
||||||
isVariadic: boolean;
|
isVariadic: boolean;
|
||||||
|
|
||||||
|
@ -850,7 +850,7 @@ declare namespace ts.server.protocol {
|
||||||
separatorDisplayParts: SymbolDisplayPart[];
|
separatorDisplayParts: SymbolDisplayPart[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The signature helps items for the parameters.
|
* The signature helps items for the parameters.
|
||||||
*/
|
*/
|
||||||
parameters: SignatureHelpParameter[];
|
parameters: SignatureHelpParameter[];
|
||||||
|
|
||||||
|
@ -866,17 +866,17 @@ declare namespace ts.server.protocol {
|
||||||
export interface SignatureHelpItems {
|
export interface SignatureHelpItems {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The signature help items.
|
* The signature help items.
|
||||||
*/
|
*/
|
||||||
items: SignatureHelpItem[];
|
items: SignatureHelpItem[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The span for which signature help should appear on a signature
|
* The span for which signature help should appear on a signature
|
||||||
*/
|
*/
|
||||||
applicableSpan: TextSpan;
|
applicableSpan: TextSpan;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The item selected in the set of available help items.
|
* The item selected in the set of available help items.
|
||||||
*/
|
*/
|
||||||
selectedItemIndex: number;
|
selectedItemIndex: number;
|
||||||
|
|
||||||
|
@ -900,7 +900,7 @@ declare namespace ts.server.protocol {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signature help request; value of command field is "signatureHelp".
|
* Signature help request; value of command field is "signatureHelp".
|
||||||
* Given a file location (file, line, col), return the signature
|
* Given a file location (file, line, col), return the signature
|
||||||
* help.
|
* help.
|
||||||
*/
|
*/
|
||||||
export interface SignatureHelpRequest extends FileLocationRequest {
|
export interface SignatureHelpRequest extends FileLocationRequest {
|
||||||
|
@ -931,8 +931,8 @@ declare namespace ts.server.protocol {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GeterrForProjectRequest request; value of command field is
|
* GeterrForProjectRequest request; value of command field is
|
||||||
* "geterrForProject". It works similarly with 'Geterr', only
|
* "geterrForProject". It works similarly with 'Geterr', only
|
||||||
* it request for every file in this project.
|
* it request for every file in this project.
|
||||||
*/
|
*/
|
||||||
export interface GeterrForProjectRequest extends Request {
|
export interface GeterrForProjectRequest extends Request {
|
||||||
|
@ -1002,7 +1002,7 @@ declare namespace ts.server.protocol {
|
||||||
diagnostics: Diagnostic[];
|
diagnostics: Diagnostic[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event message for "syntaxDiag" and "semanticDiag" event types.
|
* Event message for "syntaxDiag" and "semanticDiag" event types.
|
||||||
* These events provide syntactic and semantic errors for a file.
|
* These events provide syntactic and semantic errors for a file.
|
||||||
*/
|
*/
|
||||||
|
@ -1010,6 +1010,32 @@ declare namespace ts.server.protocol {
|
||||||
body?: DiagnosticEventBody;
|
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.
|
* Arguments for reload request.
|
||||||
*/
|
*/
|
||||||
|
@ -1038,7 +1064,7 @@ declare namespace ts.server.protocol {
|
||||||
export interface ReloadResponse extends Response {
|
export interface ReloadResponse extends Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arguments for saveto request.
|
* Arguments for saveto request.
|
||||||
*/
|
*/
|
||||||
export interface SavetoRequestArgs extends FileRequestArgs {
|
export interface SavetoRequestArgs extends FileRequestArgs {
|
||||||
|
@ -1114,7 +1140,7 @@ declare namespace ts.server.protocol {
|
||||||
*/
|
*/
|
||||||
kindModifiers?: string;
|
kindModifiers?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The file in which the symbol is found.
|
* The file in which the symbol is found.
|
||||||
*/
|
*/
|
||||||
file: string;
|
file: string;
|
||||||
|
@ -1161,7 +1187,7 @@ declare namespace ts.server.protocol {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change request message; value of command field is "change".
|
* Change request message; value of command field is "change".
|
||||||
* Update the server's view of the file named by argument 'file'.
|
* Update the server's view of the file named by argument 'file'.
|
||||||
* Server does not currently send a response to a change request.
|
* Server does not currently send a response to a change request.
|
||||||
*/
|
*/
|
||||||
export interface ChangeRequest extends FileLocationRequest {
|
export interface ChangeRequest extends FileLocationRequest {
|
||||||
|
|
|
@ -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 {
|
return {
|
||||||
start: project.compilerService.host.positionToLineOffset(fileName, diag.start),
|
start: project.compilerService.host.positionToLineOffset(fileName, diag.start),
|
||||||
end: project.compilerService.host.positionToLineOffset(fileName, diag.start + diag.length),
|
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 {
|
export interface PendingErrorCheck {
|
||||||
fileName: string;
|
fileName: string;
|
||||||
project: Project;
|
project: Project;
|
||||||
|
@ -178,6 +186,21 @@ namespace ts.server {
|
||||||
"\r\n\r\n" + json);
|
"\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) {
|
public event(info: any, eventName: string) {
|
||||||
const ev: protocol.Event = {
|
const ev: protocol.Event = {
|
||||||
seq: 0,
|
seq: 0,
|
||||||
|
@ -561,9 +584,9 @@ namespace ts.server {
|
||||||
*/
|
*/
|
||||||
private openClientFile(fileName: string, fileContent?: string, scriptKind?: ScriptKind) {
|
private openClientFile(fileName: string, fileContent?: string, scriptKind?: ScriptKind) {
|
||||||
const file = ts.normalizePath(fileName);
|
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) {
|
if (configFileErrors) {
|
||||||
this.event({ triggerFile: fileName, configFile: configFileName, diagnostics: configFileErrors }, "configFileDiag");
|
this.configFileDiagnosticEvent(fileName, configFileName, configFileErrors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue