LSP-typescript
TypeScript, JavaScript support for Sublime LSP plugin
Details
Installs
- Total 36K
- Win 12K
- Mac 14K
- Linux 10K
Nov 21 | Nov 20 | Nov 19 | Nov 18 | Nov 17 | Nov 16 | Nov 15 | Nov 14 | Nov 13 | Nov 12 | Nov 11 | Nov 10 | Nov 9 | Nov 8 | Nov 7 | Nov 6 | Nov 5 | Nov 4 | Nov 3 | Nov 2 | Nov 1 | Oct 31 | Oct 30 | Oct 29 | Oct 28 | Oct 27 | Oct 26 | Oct 25 | Oct 24 | Oct 23 | Oct 22 | Oct 21 | 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 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 8 | 6 | 3 | 10 | 11 | 5 | 9 | 0 | 0 | 10 | 9 | 11 | 6 | 8 | 12 | 17 | 18 | 9 | 11 | 6 | 11 | 7 | 6 | 6 | 14 | 5 | 6 | 5 | 10 | 16 | 13 | 15 | 6 | 11 | 12 | 16 | 14 | 8 | 11 | 8 | 20 | 13 | 8 | 9 | 7 | 8 |
Mac | 3 | 4 | 2 | 10 | 5 | 2 | 8 | 0 | 0 | 8 | 12 | 5 | 2 | 7 | 2 | 7 | 8 | 7 | 10 | 3 | 14 | 4 | 13 | 11 | 15 | 6 | 6 | 12 | 9 | 10 | 13 | 8 | 5 | 2 | 11 | 6 | 12 | 9 | 9 | 5 | 12 | 9 | 10 | 10 | 11 | 10 |
Linux | 3 | 5 | 1 | 9 | 9 | 6 | 4 | 0 | 0 | 6 | 9 | 6 | 7 | 6 | 8 | 11 | 12 | 13 | 10 | 7 | 6 | 5 | 6 | 5 | 7 | 9 | 7 | 5 | 7 | 3 | 3 | 7 | 5 | 7 | 8 | 10 | 7 | 12 | 12 | 13 | 4 | 7 | 17 | 6 | 8 | 19 |
Readme
- Source
- raw.githubusercontent.com
LSP-typescript
TypeScript and JavaScript support for Sublime's LSP plugin provided through TypeScript Language Server.
Installation
- Install
LSP
andLSP-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 symbolssource.fixAll.ts
- despite the name, fixes a couple of specific issues: unreachable code, await in non-async functions, incorrectly implemented interfacesource.organizeImports.ts
- organizes and removes unused importssource.removeUnused.ts
- removes declared but unused variablessource.removeUnusedImports.ts
- removes unused importssource.sortImports.ts
- sorts 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.
To enable inlay hints:
- Open the command palette and select
Preferences: LSP Settings
, then enableshow_inlay_hints
:
{
"show_inlay_hints": true
}
- 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.