typescript-language-server
Language Server Protocol (LSP) implementation for TypeScript using tsserver
Last updated 7 years ago by svenefftinge .
Apache-2.0 · Repository · Original npm · Tarball · package.json
$ npm install typescript-language-server 
SYNC missed versions from official npm registry.

Discord npm version npm downloads

TypeScript Language Server

Language Server Protocol implementation for TypeScript wrapping tsserver.

Based on concepts and ideas from https://github.com/prabirshrestha/typescript-language-server and originally maintained by TypeFox.

Maintained by a community of contributors like you.

Installing

npm install -g typescript-language-server typescript

Running the language server

typescript-language-server --stdio

CLI Options

  Usage: typescript-language-server [options]


  Options:

    -V, --version                          output the version number
    --stdio                                use stdio (required option)
    --log-level <log-level>                A number indicating the log level (4 = log, 3 = info, 2 = warn, 1 = error). Defaults to `3`.
    -h, --help                             output usage information

Configuration

See configuration documentation.

Features

Code actions on save

Server announces support for the following code action kinds:

  • source.fixAll.ts - despite the name, fixes a couple of specific issues: unreachable code, await in non-async functions, incorrectly implemented interface
  • source.removeUnused.ts - removes declared but unused variables
  • source.addMissingImports.ts - adds imports for used but not imported symbols
  • source.removeUnusedImports.ts - removes unused imports
  • source.sortImports.ts - sorts imports
  • source.organizeImports.ts - organizes and removes unused imports

This allows editors that support running code actions on save to automatically run fixes associated with those kinds.

Those code actions, if they apply in the current code, should also be presented in the list of "Source Actions" if the editor exposes those.

The user can enable it with a setting similar to (can vary per-editor):

"codeActionsOnSave": {
    "source.organizeImports.ts": true,
    // or just
    "source.organizeImports": true,
}

Workspace commands (workspace/executeCommand)

See LSP specification.

Most of the time, you'll execute commands with arguments retrieved from another request like textDocument/codeAction. There are some use cases for calling them manually.

lsp refers to the language server protocol types, tsp refers to the typescript server protocol types.

Go to Source Definition

  • Request:
    {
        command: `_typescript.goToSourceDefinition`
        arguments: [
            lsp.DocumentUri,  // String URI of the document
            lsp.Position,     // Line and character position (zero-based)
        ]
    }
    
  • Response:
    lsp.Location[] | null
    

(This command is supported from Typescript 4.7.)

Apply Workspace Edits

  • Request:
    {
        command: `_typescript.applyWorkspaceEdit`
        arguments: [lsp.WorkspaceEdit]
    }
    
  • Response:
    lsp.ApplyWorkspaceEditResult
    

Apply Code Action

  • Request:
    {
        command: `_typescript.applyCodeAction`
        arguments: [
            tsp.CodeAction,  // TypeScript Code Action object
        ]
    }
    
  • Response:
    void
    

Apply Refactoring

  • Request:
    {
        command: `_typescript.applyRefactoring`
        arguments: [
            tsp.GetEditsForRefactorRequestArgs,
        ]
    }
    
  • Response:
    void
    

Organize Imports

  • Request:
    {
        command: `_typescript.organizeImports`
        arguments: [
            // The "skipDestructiveCodeActions" argument is supported from Typescript 4.4+
            [string] | [string, { skipDestructiveCodeActions?: boolean }],
        ]
    }
    
  • Response:
    void
    

Rename File

  • Request:
    {
        command: `_typescript.applyRenameFile`
        arguments: [
            { sourceUri: string; targetUri: string; },
        ]
    }
    
  • Response:
    void
    

Configure plugin

  • Request:
    {
        command: `_typescript.configurePlugin`
        arguments: [pluginName: string, configuration: any]
    }
    
  • Response:
    void
    

Code Lenses (textDocument/codeLens)

Code lenses can be enabled using the implementationsCodeLens and referencesCodeLens workspace configuration options.

Code lenses provide a count of references and/or implemenations for symbols in the document. For clients that support it it's also possible to click on those to navigate to the relevant locations in the the project. Do note that clicking those trigger a editor.action.showReferences command which is something that client needs to have explicit support for. Many do by default but some don't. An example command will look like this:

command: {
    title: '1 reference',
    command: 'editor.action.showReferences',
    arguments: [
        'file://project/foo.ts',    // URI
        { line: 1, character: 1 },  // Position
        [                           // A list of Location objects.
            {
                uri: 'file://project/bar.ts',
                range: {
                    start: {
                        line: 7,
                        character: 24,
                    },
                    end: {
                        line: 7,
                        character: 28,
                    },
                },
            },
        ],
    ],
}

Inlay hints (textDocument/inlayHint)

For the request to return any results, some or all of the following options need to be enabled through preferences:

export interface InlayHintsOptions extends UserPreferences {
    includeInlayParameterNameHints: 'none' | 'literals' | 'all';
    includeInlayParameterNameHintsWhenArgumentMatchesName: boolean;
    includeInlayFunctionParameterTypeHints: boolean;
    includeInlayVariableTypeHints: boolean;
    includeInlayVariableTypeHintsWhenTypeMatchesName: boolean;
    includeInlayPropertyDeclarationTypeHints: boolean;
    includeInlayFunctionLikeReturnTypeHints: boolean;
    includeInlayEnumMemberValueHints: boolean;
}

TypeScript Version Notification

Right after initializing, the server sends a custom $/typescriptVersion notification that carries information about the version of TypeScript that is utilized by the server. The editor can then display that information in the UI.

The $/typescriptVersion notification params include two properties:

  • version - a semantic version (for example 4.8.4)
  • source - a string specifying whether used TypeScript version comes from the local workspace (workspace), is explicitly specified through a initializationOptions.tsserver.path setting (user-setting) or was bundled with the server (bundled)

Development

Build

yarn build

Dev

Build and rebuild on change.

yarn dev

Test

  • yarn test - run all tests in watch mode for developing
  • yarn test:commit - run all tests once

By default only console logs of level warning and higher are printed to the console. You can override the CONSOLE_LOG_LEVEL level in package.json to either log, info, warning or error to log other levels.

Publishing

The project uses https://github.com/google-github-actions/release-please-action Github action to automatically release new version on merging a release PR.

Current Tags

  • 4.3.3                                ...           latest (a year ago)
  • 3.3.3-0                                ...           logs (a year ago)

136 Versions

  • 4.3.3                                ...           a year ago
  • 4.3.2                                ...           a year ago
  • 4.3.1                                ...           a year ago
  • 4.3.0                                ...           a year ago
  • 4.2.0                                ...           a year ago
  • 4.1.3                                ...           a year ago
  • 4.1.2                                ...           a year ago
  • 4.1.1                                ...           a year ago
  • 4.1.0                                ...           a year ago
  • 4.0.0                                ...           a year ago
  • 3.3.3-0                                ...           a year ago
  • 3.3.2                                ...           2 years ago
  • 3.3.1                                ...           2 years ago
  • 3.3.0                                ...           2 years ago
  • 3.2.0                                ...           2 years ago
  • 3.1.0                                ...           2 years ago
  • 3.0.3                                ...           2 years ago
  • 3.0.2                                ...           2 years ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.3.0                                ...           2 years ago
  • 2.2.0                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.11.2                                ...           3 years ago
  • 0.11.1                                ...           3 years ago
  • 0.11.0                                ...           3 years ago
  • 0.10.1                                ...           3 years ago
  • 0.10.0                                ...           3 years ago
  • 0.9.7                                ...           3 years ago
  • 0.9.6                                ...           3 years ago
  • 0.9.5                                ...           3 years ago
  • 0.9.4                                ...           3 years ago
  • 0.9.3                                ...           3 years ago
  • 0.9.2                                ...           3 years ago
  • 0.9.1                                ...           3 years ago
  • 0.9.0                                ...           3 years ago
  • 0.8.1                                ...           3 years ago
  • 0.8.0                                ...           3 years ago
  • 0.7.1                                ...           3 years ago
  • 0.7.0                                ...           3 years ago
  • 0.6.5                                ...           3 years ago
  • 0.6.4                                ...           3 years ago
  • 0.6.3                                ...           3 years ago
  • 0.6.2                                ...           3 years ago
  • 0.6.1                                ...           3 years ago
  • 0.6.0                                ...           3 years ago
  • 0.5.4                                ...           3 years ago
  • 0.5.2 [deprecated]           ...           3 years ago
  • 0.5.1                                ...           4 years ago
  • 0.5.0                                ...           4 years ago
  • 0.4.0                                ...           5 years ago
  • 0.4.0-dev.42dcf0d                                ...           5 years ago
  • 0.3.8                                ...           6 years ago
  • 0.4.0-next.95a0000                                ...           6 years ago
  • 0.4.0-dev.74a2836                                ...           6 years ago
  • 0.4.0-dev.acc1561                                ...           6 years ago
  • 0.4.0-dev.01522fe                                ...           6 years ago
  • 0.4.0-dev.ce6b943                                ...           6 years ago
  • 0.4.0-dev.12aa8ed                                ...           6 years ago
  • 0.4.0-dev.4b3531e                                ...           6 years ago
  • 0.4.0-dev.d7a76a1                                ...           6 years ago
  • 0.4.0-dev.e032d7d                                ...           6 years ago
  • 0.3.7                                ...           6 years ago
  • 0.4.0-dev.9e83a6b                                ...           6 years ago
  • 0.4.0-dev.5e314a9                                ...           6 years ago
  • 0.4.0-dev.e997af1                                ...           6 years ago
  • 0.4.0-dev.b361793                                ...           6 years ago
  • 0.3.6                                ...           6 years ago
  • 0.4.0-dev.3a9d7e7                                ...           6 years ago
  • 0.3.5                                ...           6 years ago
  • 0.4.0-dev.366aecb                                ...           6 years ago
  • 0.4.0-dev.b964d21                                ...           6 years ago
  • 0.3.4                                ...           6 years ago
  • 0.4.0-dev.a1b151f                                ...           6 years ago
  • 0.3.3                                ...           6 years ago
  • 0.4.0-dev.5cc9b6f                                ...           6 years ago
  • 0.3.2                                ...           6 years ago
  • 0.4.0-dev.2ab20b1                                ...           6 years ago
  • 0.3.1                                ...           6 years ago
  • 0.2.1                                ...           6 years ago
  • 0.3.0-dev.9ab4981                                ...           6 years ago
  • 0.3.0-dev.bb5135e                                ...           6 years ago
  • 0.3.0                                ...           6 years ago
  • 0.3.0-dev.ceb1d15                                ...           6 years ago
  • 0.3.0-next.7704bd8                                ...           6 years ago
  • 0.3.0-next.a6cf729                                ...           6 years ago
  • 0.3.0-next.f632250                                ...           6 years ago
  • 0.3.0-next.5dc5868                                ...           6 years ago
  • 0.3.0-next.2bbd5d0                                ...           6 years ago
  • 0.3.0-next.3eab5c2                                ...           6 years ago
  • 0.3.0-next.3538b6a                                ...           6 years ago
  • 0.3.0-next.1e8dc72                                ...           6 years ago
  • 0.3.0-next.1142129                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.2.0-next.2                                ...           6 years ago
  • 0.2.0-next.1                                ...           6 years ago
  • 0.2.0-next.0                                ...           6 years ago
  • 0.1.14                                ...           7 years ago
  • 0.1.12                                ...           7 years ago
  • 0.1.11                                ...           7 years ago
  • 0.1.10                                ...           7 years ago
  • 0.1.9                                ...           7 years ago
  • 0.1.8                                ...           7 years ago
  • 0.1.7                                ...           7 years ago
  • 0.1.6                                ...           7 years ago
  • 0.1.5                                ...           7 years ago
  • 0.1.4                                ...           7 years ago
  • 0.1.3                                ...           7 years ago
  • 0.1.2                                ...           7 years ago
  • 0.1.1                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
  • 0.0.19                                ...           7 years ago
  • 0.0.18                                ...           7 years ago
  • 0.0.17                                ...           7 years ago
  • 0.0.16                                ...           7 years ago
  • 0.0.15                                ...           7 years ago
  • 0.0.14                                ...           7 years ago
  • 0.0.13                                ...           7 years ago
  • 0.0.12                                ...           7 years ago
  • 0.0.11                                ...           7 years ago
  • 0.0.10                                ...           7 years ago
  • 0.0.9                                ...           7 years ago
  • 0.0.8                                ...           7 years ago
  • 0.0.7                                ...           7 years ago
  • 0.0.6                                ...           7 years ago
  • 0.0.5                                ...           7 years ago
  • 0.0.3                                ...           7 years ago
  • 0.0.2                                ...           7 years ago
  • 0.0.1                                ...           7 years ago
Maintainers (2)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (11)
Dependents (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE