Sublime LSP Plugin Documentation

Configuration

LSP Settings

Global plugin settings and settings defined at project level are merged together.

Language Specific Setup

Install and verify Sublime Text can find the language server executable through the PATH, especially when using virtual environments with your interpreter.

Run "LSP: Enable Language Server" from Sublime's Command Palette to allow LSP to start a server when a document with a certain syntax is opened/activated.

LSP registers a server's supported trigger characters with Sublime Text. If completion on . or ->, is not working, you may need to add the listed auto_complete_triggers to your User or Syntax-specific settings.

The default LSP.sublime-settings contains some default LSP client configuration that may not work for you. See Client Config for explanations for the available settings.

Javascript/Typescript

You need to have tomv564/lsp-tsserver installed globally for the completions to work.

npm install -g lsp-tsserver

Client configuration:

{
    "js": {
        "command": ["lsp-tsserver"],
        "enabled": true,
        "languageId": "javascript",
        "scopes": ["source.js"],
        "syntaxes": ["Packages/JavaScript/JavaScript.sublime-syntax"]
    },
    "jsts": {
        "command": ["lsp-tsserver"],
        "enabled": true,
        "languageId": "typescript",
        "scopes": ["source.ts", "source.tsx"],
        "syntaxes": ["Packages/TypeScript-TmLanguage/TypeScript.tmLanguage", "Packages/TypeScript-TmLanguage/TypeScriptReact.tmLanguage"],
    }
}

Flow (Javascript)

See: github

Client configuration:

      "flow":
      {
        "command": ["flow-language-server", "--stdio"],
        "scopes": ["source.js"],
        "syntaxes": ["Packages/Babel/JavaScript (Babel).sublime-syntax", "Packages/JavaScript/JavaScript.sublime-syntax"],
        "languageId": "javascript"
      }

Vue (Javascript)

See: npm package

Client configuration:

"vue-ls":{
  "command": [
    "node",
    "/ABSOLUTE/PATH/TO/SERVER/.npm-global/bin/vls"
  ],
  "enabled": true,
  "languageId": "vue",
  "scopes": [
    "text.html.vue"
  ],
  "syntaxes": [
    // For ST3 builds < 3153
    "Packages/Vue Syntax Highlight/vue.tmLanguage"
    // For ST3 builds >= 3153
    // "Packages/Vue Syntax Highlight/Vue Component.sublime-syntax"
  ]
}

Be sure to install "Vue Syntax Highlight" from Package Control.

Python

pip install python-language-server

See: github:palantir/python-language-server

Alternatively, Microsoft's python language server (using .NET Core runtime)

Instructions here

PHP

UPDATE: Some new options for PHP language servers are discussed in this issue

PHP Language server

  1. modify ~/.composer/composer.json to set
"minimum-stability": "dev",
"prefer-stable": true,
  1. run composer global require felixfbecker/language-server
  2. run composer run-script --working-dir=~/.composer/vendor/felixfbecker/language-server parse-stubs
  3. modify LSP.sublime-settings - User
{
  "clients": {
    "phpls": {
      "command": ["php", "/PATH-TO-HOME-DIR/.composer/vendor/felixfbecker/language-server/bin/php-language-server.php"],
      "scopes": ["source.php"],
      "syntaxes": ["Packages/PHP/PHP.sublime-syntax"],
      "languageId": "php"
    }
  }
}
  1. (optional) add triggers to Preferences.sublime-settings - User
"auto_complete_triggers":
[
  {
    "characters": "$>:\\",
    "selector": "source.php"
  }
]

See: github:felixfbecker/php-language-server

Intelephense

See bmewburn/intelephense-server/

 "intelephense-ls":
  {
      // npm i -g intelephense-server
      "enabled": true,
      "command": [
          "node",
          "PATH_TO_GLOBAL_NODE_MODULES/intelephense-server/lib/server.js",
          "--stdio",
      ],
      "scopes": ["source.php", "embedding.php"],
      "syntaxes": ["Packages/PHP/PHP.sublime-syntax"],
      "languageId": "php",
      "initializationOptions": {
          "storagePath": "PATH_TO_TEMP_FOLDER/intelephense-ls",
      },
  },

Ruby / Ruby on Rails

Requires the solargraph gem:

gem install solargraph

See github.com:castwide/solargraph for up-to-date installation instructions.

Client configuration:

"ruby": {
    "command":
    [
        "solargraph",
        "socket"
    ],
    "enabled": true,
    "languageId": "ruby",
    "scopes":
    [
        "source.ruby",
        "source.ruby.rails"
    ],
    "syntaxes":
    [
        "Packages/Ruby/Ruby.sublime-syntax",
        "Packages/Rails/Ruby on Rails.sublime-syntax",
        "Packages/Rails/HTML (Rails).sublime-syntax"
    ],
    "tcp_port": 7658
},

Rust

Requires Rust Nightly.

See github:rust-lang-nursery/rls for up-to-date installation instructions.

Scala

SBT 1.x supports limited language server functionality, setup is described here: sbt server with Sublime Text 3.

Dotty, the future scala compiler contains LSP support. It is developed against VS Code, so ignore instructions related to VS Code.

Get the project compiling with dotty first (see https://github.com/lampepfl/dotty-example-project#using-dotty-in-an-existing-project)

At this point LSP should complain in the logs java.util.concurrent.CompletionException: java.io.FileNotFoundException: /Users/tomv/Projects/tomv564/dottytest/finagle/doc/src/sphinx/code/quickstart/.dotty-ide.json

Then run sbt configureIDE to create the .dotty-ide.json file Then the LSP plugin should launch as configured in LSP.sublime-settings using coursier.

C/C++ (Clangd)

You will need to build from source, see instructions

For any project of non-trivial size, you probably have a build system in place to compile your source files. The compilation command passed to your compiler might include things like:

Like any language server, clangd works on a per-file (or per-buffer) basis. But unlike most other language servers, it must also be aware of the exact compile flags that you pass to your compiler. For this reason, people have come up with the idea of a compilation database. At this time, this is just a simple JSON file that describes for each translation unit (i.e. a .cpp, .c, .m or .mm file) the exact compilation flags that you pass to your compiler.

It's pretty much standardized that this file should be called compile_commands.json. clangd searches for this file up in parent directories from the currently active document. If you don't have such a file present, most likely clangd will spit out nonsense errors and diagnostics about your code.

As it turns out, CMake can generate this file for you if you pass it the cache variable -DCMAKE_EXPORT_COMPILE_COMMANDS=ON when invoking CMake. It will be present in your build directory, and you can copy that file to the root of your project. Make sure to ignore this file in your version control system.

Since header files are (usually) not passed to a compiler, they don't have compile commands. So even with a compilation database in place, clangd will still spit out nonsense in header files. You can try to remedy this by enhancing your compilation database with your header files using this project called compdb.

To generate headers with compdb, read this closed issue.

You can also read about attempts to address this on the CMake issue tracker, along with the problem of treating header files as translation units.

Ocaml/Reason

You will need to install sublime-reason and the dependencies listed in the repo, such as ocaml-language-server. If you only use OCaml, you still need those listed dependencies, but not the sublime-reason plugin itself.

Go

NOTE: This language server is missing completions and diagnostics support. You may be better served by the GoSublime package.

go get github.com/sourcegraph/go-langserver

See: github:palantir/sourcegraphgo-langserver

Client configuration:

"golsp":
{
  "command": ["go-langserver"],
  "enabled": true,
  "scopes": ["source.go"],
  "syntaxes": ["Packages/Go/Go.sublime-syntax"],
  "languageId": "go"
},

CSS

Using the VS Code CSS language server:

npm install -g vscode-css-languageserver-bin

Then add to your LSP settings (replace PATH_TO_NODE_MODULES):

"vscode-css":
  {
    "command": ["node", "PATH_TO_NODE_MODULES/vscode-css-languageserver-bin/cssServerMain.js", "--stdio"],
    "scopes": ["source.css"],
    "syntaxes": ["Packages/CSS/CSS.sublime-syntax"],
    "languageId": "css"
  },

Polymer

npm install -g polymer-editor-service

Note: requires an up to date version of NodeJS. v6 is the minimum supported version as of 2017.

Features:

More info: https://github.com/Polymer/polymer-editor-service

Dart

pub global activate dart_language_server

See: natebosch/dart_language_server

Client configuration (replace PATH_TO_PUB_BIN):

"dart": {
  "command": [
    "PATH_TO_PUB_BIN/dart_language_server"
  ],
  "enabled": true,
  "languageId": "dart",
  "scopes": [
    "source.dart"
  ],
  "syntaxes": [
    "Packages/Dart/Dart.tmLanguage"
  ]
}

Kotlin

Install from kotlin language server Requires building first.

"kotlinls":
{
    "command":
    [
        "PATH_TO_KotlinLanguageServer/build/install/kotlin-language-server/bin/kotlin-language-server.bat" // adjust this path!
    ],
    "enabled": true,
    "languageId": "kotlin",
    "scopes":
    [
        "source.Kotlin"
    ],
    "syntaxes":
    [
        "Packages/kotlin/Kotlin.tmLanguage"
    ]
}

Additionally, install the Kotlin sublime package for syntax highlighting.

Bash

Install the bash language server

npm i -g bash-language-server

Settings:

"bashls":
{
    "command":
    [
        "bash-language-server", // add .cmd on windows
        "start"
    ],
    "enabled": true,
    "languageId": "bash",
    "scopes":
    [
        "source.shell.bash"
    ],
    "syntaxes":
    [
        "Packages/ShellScript/Bash.sublime-syntax"
    ]
}

IntelliJ

Requires IntelliJ to be running.

"intellij":{
  "tcp_port": 8080 // default port
  "command": [],
  "languageId": "java",
  "scopes": [
    "source.java"
  ],
  "syntaxes": [
    "Packages/Java/Java.sublime-syntax"
  ]
}

Other

Please create issues / pull requests so we can get support for more languages.

Client Configuration

LSP ships with default client configuration for a few language servers. These configurations need to be enabled before they will start.

Here is an example for the Javascript/Typescript server:

"jsts": {
    "command": ["lsp-tsserver"],
    "scopes": ["source.ts", "source.tsx"],
    "syntaxes": ["Packages/TypeScript-TmLanguage/TypeScript.tmLanguage", "Packages/TypeScript-TmLanguage/TypeScriptReact.tmLanguage"],
    "languageId": "typescript"
}

Client configurations can be customized as follows by adding an override in the User LSP.sublime-settings

Per-project overrides

Any fields in a client configuration can be overridden by adding an LSP settings block to your .sublime-project file:

{
  "folders":
  [
    {
      "path": "."
    }
  ],
  "settings": {
    "LSP": {
      "jsts": {
        "enabled": false,
      },
      "eslintls": {
        "settings": {
          "eslint": {
            "autoFixOnSave": true
          }
        }
      }
    }
  }
}

Features

Plugin commands

Document actions

Workspace actions

Show Diagnostics Panel: super+shift+M / ctr+alt+M

Overriding keybindings

Sublime's keybindings can be edited from the Preferences: Key Bindings command. The following example overrides f12 to use LSP's go to definition when in javascript/typescript:

{
    "keys": ["f12"],
    "command": "lsp_symbol_definition",
    "context": [
        {
            "key": "selector",
            "operator": "equal",
            "operand": "source.ts, source.js"
        }
    ]
}

More useful keybindings (OS-X), edit Package Settings -> LSP -> Key Bindings

  { "keys": ["f2"], "command": "lsp_symbol_rename" },
  { "keys": ["f12"], "command": "lsp_symbol_definition" },
  { "keys": ["super+option+r"], "command": "lsp_document_symbols" },
  { "keys": ["super+option+h"], "command": "lsp_hover"}

Mouse map configuration

See below link, but bind to lsp_symbol_definition command https://stackoverflow.com/questions/16235706/sublime-3-set-key-map-for-function-goto-definition

Troubleshooting

First step should be to set the log_debug setting to true, restart sublime and examine the output in the Sublime console. log_stderr can also be set to true to see the language server's own logging.

LSP doesn't try to start my language server

Your client configuration requires two settings to match the document your are editing:

LSP cannot find my language server through PATH on OS-X

This issue can be solved in a few ways: