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

LSP-typescript

by sublimelsp ST3

TypeScript, JavaScript support for Sublime LSP plugin

Details

  • 1.11.0
    1.9.1
  • github.​com
  • github.​com
  • 5 days ago
  • 3 hours ago
  • 2 years ago

Installs

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

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 ST4: The TypeScript and React (TSX) syntaxes are built-in so no need to install anything else.
  • For ST3: If you are working with TypeScript install TypeScript Syntax. If you are working with React install JSCustom.
  • 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}"]
        }
    },

Code Actions on Save

Server supports the following code actions that can be specified in the global lsp_code_actions_on_save setting and run on saving files:

  • source.addMissingImports.ts - adds imports for used but not imported symbols
  • 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.organizeImports.ts - organizes and removes unused imports

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.