Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ts_ls

URL: https://github.com/typescript-language-server/typescript-language-server

plugins.lsp.servers.ts_ls.enable

Whether to enable https://github.com/typescript-language-server/typescript-language-server

ts_ls, aka typescript-language-server, is a Language Server Protocol implementation for TypeScript wrapping tsserver. Note that ts_ls is not tsserver.

While typescript-language-server will likely eventually be replaced by tsc, the official language server for TypeScript, typescript-language-server may still be useful for features such as es5 support.

typescript-language-server depends on typescript. Both packages can be installed via npm:

# if you are using `ts_ls` you will need to install a `typescript` version < 7 for now
npm install -g typescript@<version> typescript-language-server

To configure typescript language server, add a tsconfig.json or jsconfig.json to the root of your project.

Here’s an example that disables type checking in JavaScript files.

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "checkJs": false
  },
  "exclude": [
    "node_modules"
  ]
}

If you also have a deno.json or a deno.jsonc in your project, the ts_ls may not start (depending where the deno.json is)

Use the :LspTypescriptSourceAction command to see “whole file” (“source”) code-actions such as: - organize imports - remove unused code

Use the :LspTypescriptGoToSourceDefinition command to navigate to the source definition of a symbol (e.g., jump to the original implementation instead of type definitions).

Monorepo support

See the monorepo support documentation for tsc.

Type: boolean

Default:

false

Example:

true

Declared by:

plugins.lsp.servers.ts_ls.package

The ts_ls package to use.

Alternatively, ts_ls should be installed on your $PATH.

Type: null or package

Default:

pkgs.typescript-language-server

Declared by:

plugins.lsp.servers.ts_ls.packageFallback

When enabled, the language server package will be added to the end of the PATH (suffix) instead of the beginning (prefix).

This can be useful if you want local versions of the language server (e.g. from a devshell) to override the Nixvim version.

Type: boolean

Default:

false

Declared by:

plugins.lsp.servers.ts_ls.autostart

Whether to call vim.lsp.enable() for ts_ls.

Type: boolean

Default:

true

Example:

false

Declared by:

plugins.lsp.servers.ts_ls.cmd

A list where each entry corresponds to the blankspace delimited part of the command that launches the server.

The first entry is the binary used to run the language server. Additional entries are passed as arguments.

Type: null or (list of string)

Default: null when package is null, otherwise null

Declared by:

plugins.lsp.servers.ts_ls.extraOptions

Extra options for the ts_ls language server.

Type: attribute set of anything

Default:

{ }

Declared by:

plugins.lsp.servers.ts_ls.filetypes

Set of filetypes for which to attempt to resolve {root_dir}. May be empty, or server may specify a default value.

Type: null or (list of string)

Default:

null

Declared by:

plugins.lsp.servers.ts_ls.rootMarkers

A list of files that mark the root of the project/workspace.

Vim’s LSP will try to share the same language server instance for all buffers matching filetypes within the same project.

A new server instance is only spawned when opening a buffer with a different project root.

See :h lsp-config and :h vim.fs.root().

Type: null or (list of (string or raw lua code)) or raw lua code

Default: null

Plugin default: null

Declared by:

plugins.lsp.servers.ts_ls.settings

The settings for this LSP.

Type: open submodule of attribute set of lua value

Default:

{ }

Example:

{
  callback = lib.nixvim.mkRaw ''
  function()
    print('nixvim')
  end
'';
  foo_bar = 42;
  hostname = "localhost:8080";
}

Declared by: