• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created about 5 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

TypeScript, JavaScript support for Sublime LSP plugin

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.

More Repositories

1

LSP

Client implementation of the Language Server Protocol for Sublime Text
Python
1,645
star
2

LSP-pyright

Python support for Sublime's LSP plugin provided through microsoft/pyright.
Python
127
star
3

LSP-intelephense

PHP support for Sublime's LSP plugin provided through intelephense.
Python
96
star
4

LSP-volar

Vue support for Sublime's LSP plugin
Python
84
star
5

LSP-json

Schema validation/completions for your JSON and Sublime files
Python
73
star
6

LSP-pylsp

Convenience package for the Python Language Server
Shell
72
star
7

LSP-rust-analyzer

Convenience package for rust-analyzer
Python
70
star
8

LSP-tailwindcss

Tailwind css support for Sublime's LSP plugin
Python
55
star
9

LSP-gopls

Golang support for Sublime's LSP plugin
Python
48
star
10

LSP-clangd

C/C++ support for Sublime's LSP plugin provided through clangd.
Python
42
star
11

LSP-elixir

Elixir support for Sublime LSP plugin
Python
41
star
12

LSP-css

CSS, SCSS, LESS support for Sublime's LSP plugin
JavaScript
37
star
13

LSP-eslint

ESLint support for Sublime LSP plugin
JavaScript
36
star
14

LSP-html

HTML support for Sublime's LSP plugin
JavaScript
35
star
15

LSP-ruff

LSP helper for ruff - an extremely fast Python linter, written in Rust.
Python
31
star
16

LSP-jdtls

Convenience package for the Eclipse JDT language server
Python
30
star
17

LSP-vue

Vue support for Sublime's LSP plugin
Python
27
star
18

LSP-bash

Bash support for Sublime's LSP plugin provided through bash-language-server.
Python
25
star
19

LSP-Grammarly

Grammarly support for Sublime's LSP plugin, using the Grammarly language server
Python
25
star
20

LSP-lua

Convenience package with a lua language server bundled
Python
24
star
21

LSP-julia

Julia support for Sublime's LSP plugin using LanguageServer.jl
Python
23
star
22

LSP-yaml

YAML support for Sublime's LSP plugin using yaml-language-server
Python
21
star
23

LSP-OmniSharp

Convenience plugin to install/update OmniSharp for LSP
Python
20
star
24

LSP-Dart

Convenience plugin for the Dart Analysis Server, bundled in the Dart SDK
Python
18
star
25

LSP-file-watcher-chokidar

Chokidar-based file watcher implementation for LSP
Python
18
star
26

LSP-biome

Biome LSP server for Sublime Text
Python
17
star
27

LSP-svelte

Convenience plugin for Svelte Language Tools
Python
16
star
28

LSP-TexLab

LaTeX support for Sublime's LSP plugin provided through latex-lsp/texlab.
Python
16
star
29

LSP-SourceKit

Convenience plugin for Apple's SourceKit language server
Python
15
star
30

LSP-marksman

An LSP server for Markdown provided through Marksman.
Python
14
star
31

LSP-dockerfile

Dockerfile support for Sublime's LSP plugin
Python
13
star
32

lsp_utils

Module with LSP-related utilities for Sublime Text
Python
13
star
33

LSP-lemminx

XML support for Sublime's LSP plugin
Python
11
star
34

LSP-Deno

Convenience package for starting the deno lsp server
Python
11
star
35

LSP-SonarLint

Linting from SonarSource
Python
11
star
36

LSP-terraform

Convenience package for the terraform language server
Python
10
star
37

LSP-angular

Convenience plugin for Angular Language Service
Python
9
star
38

LSP-cspell

Spell check support for Sublime's LSP plugin provided through cspell.
JavaScript
9
star
39

LSP-graphql

GraphQL support for Sublime's LSP package
JavaScript
8
star
40

LSP-stylelint

Stylelint support for Sublime's LSP plugin
Shell
7
star
41

LSP-astro

Astro support for Sublime's LSP plugin
Python
7
star
42

LSP-elm

Elm support for Sublime's LSP plugin
Python
7
star
43

repository

Package repository for Package Control
Python
6
star
44

LSP-ltex-ls

Convenience package for the LTeX Language Server (Spell/Grammar check for LaTex and Markdown)
Python
6
star
45

LSP-PowerShellEditorServices

Convenience plugin to install and upgrade the PowerShellEditorServices language server
Python
6
star
46

LSP-performance-test

Performance Tests for LSP
Python
4
star
47

LSP-rome

Rome LSP server for Sublime LSP
Python
4
star
48

LSP-basedpyright

Python support for Sublime's LSP plugin provided through DetachHead/basedpyright.
Python
4
star
49

LSP-cmake

Convenience package for a basic cmake-language-server
Python
3
star
50

LSP-R

Convenience package for the R language server
Python
3
star
51

LSP-leo

Leo syntax and language server
Python
3
star
52

sublime_asyncio

Python
2
star
53

LSP-serenata

PHP support for Sublime's LSP plugin using Serenata
Python
2
star
54

LSP-flow

Helper package that sets up your flow LSP server automatically
Python
2
star
55

LSP-nimlangserver

A convenience package for the official Nim language server.
Python
1
star
56

LSP-kotlin

Kotlin support for Sublime's LSP package
Python
1
star