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

LSP-typescript

by sublimelsp ST3

TypeScript, JavaScript support for Sublime LSP plugin

Details

  • 2.9.0
    1.9.1
  • github.​com
  • github.​com
  • 1 month ago
  • 49 minutes ago
  • 4 years ago

Installs

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

Readme

Source
raw.​githubusercontent.​com

LSP-typescript

TypeScript and JavaScript support for Sublime's LSP plugin provided through 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

The 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

Goto Source Definition command

TypeScript 4.7+ supports Go To Source Definition. It’s similar to Go To Definition, but it never returns results inside declaration files. Instead, it tries to find corresponding implementation files (like .js or .ts files), and find definitions there — even if those files are normally shadowed by .d.ts files.

This comes in handy most often when you need to peek at the implementation of a function you're importing from a library instead of its type declaration in a .d.ts file.

Run LSP-typescript: Goto Source Definition from the Command Palette to invoke this functionality or bind lsp_typescript_goto_source_definition to a custom key binding.

Inlay hints

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

inlay-hints

To enable inlay hints:

  1. Open the command palette and select Preferences: LSP Settings, then enable show_inlay_hints:
{
  "show_inlay_hints": true
}
  1. 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.