ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

LSP-typescript

by sublimelsp ST3

TypeScript, JavaScript support for Sublime LSP plugin

Details

Installs

  • Total 7K
  • Win 2K
  • Mac 3K
  • Linux 2K
Oct 20 Oct 19 Oct 18 Oct 17 Oct 16 Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28 Sep 27 Sep 26 Sep 25 Sep 24 Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8 Sep 7 Sep 6 Sep 5
Windows 3 8 6 5 4 7 17 9 8 6 3 9 7 5 8 7 6 2 3 3 6 7 6 8 5 9 11 4 3 6 4 1 8 11 4 5 7 3 4 3 5 9 7 3 3 6
Mac 6 9 8 6 2 7 6 5 17 3 3 6 7 10 7 11 2 6 7 5 10 9 13 11 2 11 8 8 11 6 12 6 7 7 10 8 7 4 6 10 8 7 4 11 9 7
Linux 4 6 7 9 3 3 4 6 5 6 2 8 9 6 5 8 8 4 4 2 6 6 6 6 5 2 4 6 9 2 4 6 7 9 9 5 4 7 8 7 13 5 7 15 9 3

Readme

Source
raw.​githubusercontent.​com

LSP-typescript

TypeScript and JavaScript support for Sublime's LSP plugin provided through Theia TypeScript Language Server.

Installation

  • Install LSP and LSP-typescript from Package Control.
  • For ST3: If you use TypeScript install TypeScript Syntax. If you use React install JSCustom.
  • For ST4: The TypeScript and React (TSX) syntaxes are built-in so no need to install anything else.
  • Restart Sublime.

Configuration

Open the configuration file using the Command Palette Preferences: LSP-typescript Settings command or open it from the Sublime menu.

Organize Imports command

To sort or remove unused imports you can trigger the LSP-typescript: Organize Imports command from the Command Palette or create a key binding. For example:

{ "keys": ["ctrl+k"], "command": "lsp_execute",
        "args": {
            "session_name": "LSP-typescript",
            "command_name": "_typescript.organizeImports",
            "command_args": ["${file}"]
        }
    },

Find Callers command

The LSP-typescript: Find Callers command can be used to find what is calling the given symbol. It has some overlap with the built-in LSP: Find References command but returns only the places where the symbol was called.

Inlay hints (experimental)

Inlay hints are short textual annotations that show parameter names, type hints.

inlay-hints

To enable inlay hints, modify the following settings through Preferences: LSP-typescript Settings:

{
  "settings": {
    // Javascript inlay hints options.
    "javascript.inlayHints.includeInlayEnumMemberValueHints": false,
    "javascript.inlayHints.includeInlayFunctionLikeReturnTypeHints": false,
    "javascript.inlayHints.includeInlayFunctionParameterTypeHints": false,
    "javascript.inlayHints.includeInlayParameterNameHints": "none",
    "javascript.inlayHints.includeInlayParameterNameHintsWhenArgumentMatchesName": false,
    "javascript.inlayHints.includeInlayPropertyDeclarationTypeHints": false,
    "javascript.inlayHints.includeInlayVariableTypeHints": false,
    // Typescript inlay hints options.
    "typescript.inlayHints.includeInlayEnumMemberValueHints": false,
    "typescript.inlayHints.includeInlayFunctionLikeReturnTypeHints": false,
    "typescript.inlayHints.includeInlayFunctionParameterTypeHints": false,
    "typescript.inlayHints.includeInlayParameterNameHints": "none",
    "typescript.inlayHints.includeInlayParameterNameHintsWhenArgumentMatchesName": false,
    "typescript.inlayHints.includeInlayPropertyDeclarationTypeHints": false,
    "typescript.inlayHints.includeInlayVariableTypeHints": false,
  }
}

Note: Inlay hints require TypeScript 4.4+.

Usage in projects that also use Flow

TypeScript can check vanilla JavaScript, but may break on JavaScript with Flow types in it. To keep LSP-typescript enabled for TS and vanilla JS, while ignoring Flow-typed files, you must install JSCustom and configure it like so:

{
  "configurations": {
    "Flow": {
      "scope": "source.js.flow",
      "flow_types": true,
      "jsx": true
    }
  }
}

Also install ApplySyntax and configure it like so:

{
  "syntaxes": [
    {
      "syntax": "User/JS Custom/Syntaxes/Flow",
      "match": "all",
      "rules": [
        { "file_path": ".*\\.jsx?$" },
        { "first_line": "^/[/\\*] *@flow" }
      ]
    }
  ]
}

And then configure LSP-typescript like so:

{
  "selector": "source.js - source.js.flow, source.jsx, source.ts, source.tsx"
}

This works only on Sublime Text 4, and your project must have a // @flow or /* @flow */ in each Flow-typed file. For more information, see this issue.