A Language Server Protocol connector for Sublime Text 3.
The project is in beta mode. Feedback or issue? Please email us at [email protected] or file an issue.
The Language Server Protocol is a specification that enables advanced language capabilities in an editor independent-way. Previously, to support a given language in a given editor, an editor extension writer would have to both write the editor specific functionality as well as language analysis capabilities for each language. This means that every editor and language had different levels of capability and reliability.
With LSP, one editor extension can be written per editor, and one language server per language. Sourcegraph's master plan is to support editor and language server open source authors, let us know if you'd like to work on one!
This plugin borrows heavily from the popular Microsoft TypeScript Sublime Plugin.
This connector currently supports:
- hover operations (Sublime build >=3124)
- goto definition
- find all references
- error highlighting
Autocomplete, semantic symbol-based search, formatting utilities will soon be supported.
This plugin has been developed for use with the go-langserver language server. Sourcegraph is currently developing JavaScript/TypeScript, Python, and PHP language servers, which will also work with this adapter. Finally, any language server implementing the Language Server Protocol can be connected to this plugin.
Install the sublime-lsp
connector for Sublime Text by cloning sublime-lsp
repository into your Sublime Text 3 Packages folder:
macOS:
git clone [email protected]:sourcegraph/sublime-lsp.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/sublime-lsp
Linux:
git clone [email protected]:sourcegraph/sublime-lsp.git ~/.config/sublime-text-3/Packages/sublime-lsp
Windows:
cd "%APPDATA%\Sublime Text 3\Packages"
git clone https://github.com/sourcegraph/sublime-lsp
Install the langserver-go
binary by running go get -u github.com/sourcegraph/go-langserver/
. The go-langserver
binary should now be available via your command line.
Next, configure the LSP connector for the langserver-go
binary. To change your Sourcegraph settings, open SublimeLsp.sublime-settings
by clicking Sublime Text > Preferences > Package Settings > Sublime Lsp Connector > Settings - User
.
Add the following client descriptor into clients
section
{
...
"clients": [
{
"binary": "go-langserver",
"file_exts": ["go"],
// the go binary must be in the path
"path_additions": ["/usr/local/go/bin"],
"env": {
// GOPATH is a required argument, ~'s don't work
"GOPATH": "",
}
}
]
....
}
Finally, restart Sublime Text to start using the plugin. You may want to disable Sublime's native tooltips, as they are duplicative and interfere with this connector's tooltips.
Install the TypeScript/JavaScript LSP server the following way:
export JSTS_DIR=...
git clone https://github.com/sourcegraph/javascript-typescript-langserver $JSTS_DIR
cd $JSTS_DIR
npm install
node_modules/.bin/tsc
Please make sure that $JSTS_DIR/bin
is in $PATH
Next, register TypeScript/JavaScript LSP client. To change your Sourcegraph settings, open SublimeLsp.sublime-settings
by clicking Sublime Text > Preferences > Package Settings > Sublime Lsp Connector > Settings - User
.
Add the following client descriptor into clients
section
{
...
"clients": [
{
"binary": "javascript-typescript-stdio",
"file_exts": ["ts", "tsx", "js", "jsx"],
"path_additions": ["/path/to/jsts/bin", "/path/to/node/binary/usually/usr/local/bin"],
}
]
...
}
Finally, restart Sublime Text to start using the plugin. You may want to disable Sublime's native tooltips, as they are duplicative and interfere with this connector's tooltips.
As you navigate through Go files, when your cursor is on a symbol, you should see hover tooltips. You may have to disable Sublime's native tooltips.
Execute the Lsp: Goto definition
command, and Sublime will jump to the definition of a symbol in your workspace.
Execute the Lsp: Find all references
command, and Sublime will open up a results pane with semantic references to the symbols within your project.
As you type, the language server connector will receive diagnostics from the language server. If any errors are detected, the editor will display a tooltip when the offending text is clicked.
Run langserver-go -h
in your command line. You should see a help menu.
For hover tooltips to work, you'll need Sublime Text 3, Build 3124 (released in 9/2016). Navigate to Sublime Text > About Sublime Text
to check the version.
If you are seeing two tooltips that flicker when you hover over symbols, you may have to disable Sublime Text 3 tooltips. Navigate to Sublime Text > Preferences > Settings
, and add the following lines:
{
...
"show_definitions": false, // recommended: removes default Sublime tooltips
"index_files": false, // optional: removes default Sublime "Goto Definition" from right click
...
}
To open Sublime's command window and access LSP connector operations, just execute the following key combination:
- Linux/Windows ctrl+shift+p
- Mac command+shift+p
Any search items starting with Language Server
is provided by the LSP connector.
By default, the sublime-lsp connector includes two options to your right click menu. Find local references
and Explore code at cursor.
TBD
Found a bug, want to request a feature, or want to help Sourcegraph build the global graph of code? Send us an email at [email protected].