TypeScript LSP Configuration

The details below describe how to install and configure the TypeScript language server found here.
NOTE: This installation process assumes Node.js has been installed on the machine.

Installing the Language Server

If not installed then install TypeScript:
npm install -g typescript
Install the TypeScript Language Server:
npm install -g typescript-language-server
With the software installed test the installation by running typescript-language-server.cmd -h at the command line prompt, which should result in the following output:
Usage: typescript-language-server [options]


  -V, --version                                    output the version number
  --stdio                                          use stdio
  --node-ipc                                       use node-ipc
  --log-level <logLevel>                           A number indicating the log level (4 = log, 3 = info, 2 = warn, 1 = error). Defaults to `2`.
  --socket <port>                                  use socket. example: --socket=5000
  --tsserver-log-file <tsserverLogFile>            Specify a tsserver log file. example: --tsserver-log-file ts-logs.txt
  --tsserver-log-verbosity <tsserverLogVerbosity>  Specify a tsserver log verbosity (terse, normal, verbose). example: --tsserver-log-verbosity verbose
  --tsserver-path <path>                           Specify path to tsserver. example: --tsserver-path=tsserver.cmd
  -h, --help                                       output usage information
If that output is not produced check the installation and also check to make sure the batch file installation folder has been added to the system PATH environment variable.


Edit the TypeScript document type and in the Language Server configuration panel apply the following configuration settings:
Program Type: Batch
     Program: typescript-language-server.cmd
   Directory: C:\Users\JussiJ\AppData\Roaming\npm\
   Arguments: --stdio
IMPORTANT: The directory value must be provided and it must be the same as the folder location of the typescript-language-server.cmdfile.
If this directory is incorrectly specified the following error will be reported by the language server:
Error: Cannot find module 'C:\node_modules\typescript\bin\tsserver'

Post-Installing Changes

With these configuration settings in place, running the language server inside Zeus may result in the following error:
Error: spawn "tsserver.cmd" ENOENT
This error relates to the use of the --tsserver-path="tsserver.cmd" option.
However removing that option and running the server again will now result in the following error:
Read Error: Request initialize failed with message: Couldn't find 'tsserver.cmd' executable
Both of these issue can be traced back to a bug in the typescript-language-server\lib\tsp-client.js code and it relates to the way the client tries to spawns tsserver.cmd server.
In that file there is the following section of code:
this.logger.info(`Starting tsserver : '${this.options.tsserverPath} ${args.join(' ')}'`);
this.tsserverProc = cp.spawn(this.options.tsserverPath, args);
For the Windows OS this method of running the batch file generates the error only because batch files need to be run using the cmd.exe executable.
This issue can be fixed with the following code change which forces the use of the shell to run the tsserver-path batch file:
this.logger.info(`Starting tsserver : '${this.options.tsserverPath} ${args.join(' ')}'`);
// as the server is a Windows cmd file it needs to be run using the shell
this.tsserverProc = cp.spawn(this.options.tsserverPath, args, { shell : true });

Using the Language Server

For the TypeSscript language server to work correctly, the root folder location needs to point to a folder that contains a package.json project file.
The easiest way to achieve this result is to create a Zeus workspace in that folder location and to leave the root folder option empty. With this setup the root folder location will automatically set correctly each time the language server is started.
To test the configuration create a simple test.ts file and fire off an auto-complete request:
lsp typescript

Latest Version: Zeus 3.98y
Released: 11th March 2021