Man page - tsserver(1)
Packages contains this manual
apt-get install node-typescript
Manual
TSSERVERTSSERVER
NAMENAME
Definition
Message format
Commands
NAME
Sublime text plugin
Visual Studio Code
Tide
Neovim
NAME
Logging
Cancellation
Commandline options
NAME
tsserver - TypeScript standalone server
The TypeScript standalone server (aka tsserver ) is a node executable that encapsulates the TypeScript compiler and language services, and exposes them through a JSON protocol. tsserver is well suited for editors and IDE support.
NAME
Protocol
Definition
The server communication protocol is defined in the ts.server.protocol namespace, declared in ‘tsserverlibrary.d.ts‘ .
The executable can be found in lib folder under the typescript package.
npm install --save typescript
ls node_modules\typescript\lib\tsserver.js
Message format
tsserver listens on stdin and writes messages back to stdout .
Requests are JSON following the protocol definition. Here is an example request to open a file c:/DefinitelyTyped/gregorian-calendar/index.d.ts :
{"seq":1,"type":"request","command":"open","arguments":{"file":"c:/DefinitelyTyped/gregorian-calendar/index.d.ts"}}
Responses are augmented JSON format. The Message starts with a header with the content length followed by a line separator ( \r\n ) followed by the response body as a JSON string:
Here is an example of a response for a quickinfo command:
Content-Length: 116
{"seq":0,"type":"response","command":"quickinfo","request_seq":2,"success":false,"message":"No content available."}
Similarly events have the same format as a response.
Here is an example event for error message:
Content-Length: 261
{"seq":0,"type":"event","event":"semanticDiag","body":{"file":"c:/DefinitelyTyped/gregorian-calendar/index.d.ts","diagnostics":[{"start":{"line":264,"offset":44},"end":{"line":264,"offset":50},"text":"Binding
element ’Object’
implicitly has an ’any’ type."}]}}
Commands
tsserver supports a set of commands. The full list of commands supported by the server can be found under ts.server.protocol.CommandTypes .
Each command is
associated with a request and a response interface. For
instance command
"completions"
corresponds
to request interface
CompletionsRequest
, and response
interface defined in
CompletionsResponse
.
TSSERVER
NAME
Sample implementations
Sublime text plugin
TypeScript-Sublime-Plugin is a Sublime text plugin written in Python that uses tsserver .
Visual Studio Code
VS Code ’ s TypeScript support is implemented in TypeScript using tsserver .
Tide
Tide is an elisp implementation for emacs plugin using tsserver
Neovim
nvim-typescript
is a neovim plugin using
tsserver
TSSERVER
NAME
Advanced topics
Logging
tsserver logging is configured through the TSS_LOG environment variable.
TSS_LOG can have the following format:
[-level <terse | normal |
requestTime | verbose>]
[-traceToConsole <true | false>]
[-logToFile <true | false>]
[-file <log file path>]
Note: file defaults to __dirname\.log<PID> if not specified
Example : set TSS_LOG=-level verbose -file c:\tmp\tsserver.log
Cancellation
tsserver on startup will try to load module ./cancellationToken from the containing directory. This module should export a factory function
that accepts a list of command line arguments and returns HostCancellationToken . tsserver will use this token to check if in-flight operation should be cancelled.
NOTE: This token will be used for all operations so if one operation is cancelled and cancellation was reported through the token then when another operation is started - token should be reset into the
non-cancelled
state.
Default implementation of the cancellation token uses the presence of named pipes as a way to signal cancellation.