Merge pull request #20465 from Microsoft/dev/aozgaa/tsserverVersion

Add a status request-response for editors
This commit is contained in:
Arthur Ozga 2017-12-06 17:05:46 -08:00 committed by GitHub
commit 477c1f57a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 0 deletions

View file

@ -169,6 +169,19 @@ namespace ts.server {
allowNonTsExtensions: true // injected by tsserver
});
});
it("Status request gives ts.version", () => {
const req: protocol.StatusRequest = {
command: CommandNames.Status,
seq: 0,
type: "request"
};
const expected: protocol.StatusResponseBody = {
version: ts.version
};
assert.deepEqual(session.executeCommand(req).response, expected);
});
});
describe("onMessage", () => {
@ -220,6 +233,7 @@ namespace ts.server {
CommandNames.Saveto,
CommandNames.SignatureHelp,
CommandNames.SignatureHelpFull,
CommandNames.Status,
CommandNames.TypeDefinition,
CommandNames.ProjectInfo,
CommandNames.ReloadProjects,

View file

@ -71,6 +71,7 @@ namespace ts.server.protocol {
SignatureHelp = "signatureHelp",
/* @internal */
SignatureHelpFull = "signatureHelp-full",
Status = "status",
TypeDefinition = "typeDefinition",
ProjectInfo = "projectInfo",
ReloadProjects = "reloadProjects",
@ -216,6 +217,24 @@ namespace ts.server.protocol {
projectFileName?: string;
}
export interface StatusRequest extends Request {
command: CommandTypes.Status;
}
export interface StatusResponseBody {
/**
* The TypeScript version (`ts.version`).
*/
version: string;
}
/**
* Response to StatusRequest
*/
export interface StatusResponse extends Response {
body: StatusResponseBody;
}
/**
* Requests a JS Doc comment template for a given position
*/

View file

@ -1703,6 +1703,10 @@ namespace ts.server {
}
private handlers = createMapFromTemplate<(request: protocol.Request) => HandlerResponse>({
[CommandNames.Status]: () => {
const response: protocol.StatusResponseBody = { version };
return this.requiredResponse(response);
},
[CommandNames.OpenExternalProject]: (request: protocol.OpenExternalProjectRequest) => {
this.projectService.openExternalProject(request.arguments, /*suppressRefreshOfInferredProjects*/ false);
// TODO: GH#20447 report errors

View file

@ -4905,6 +4905,7 @@ declare namespace ts.server.protocol {
Rename = "rename",
Saveto = "saveto",
SignatureHelp = "signatureHelp",
Status = "status",
TypeDefinition = "typeDefinition",
ProjectInfo = "projectInfo",
ReloadProjects = "reloadProjects",
@ -5006,6 +5007,21 @@ declare namespace ts.server.protocol {
file: string;
projectFileName?: string;
}
interface StatusRequest extends Request {
command: CommandTypes.Status;
}
interface StatusResponseBody {
/**
* The TypeScript version (`ts.version`).
*/
version: string;
}
/**
* Response to StatusRequest
*/
interface StatusResponse extends Response {
body: StatusResponseBody;
}
/**
* Requests a JS Doc comment template for a given position
*/