sourcegraph/sublime-lsp

Name: sublime-lsp

Owner: Sourcegraph

Description: An LSP adapter for Sublime Text 3.

Forked from: Microsoft/TypeScript-Sublime-Plugin

Created: 2016-11-02 00:04:30.0

Updated: 2018-03-07 04:37:27.0

Pushed: 2017-05-02 21:03:30.0

Homepage: https://langserver.org

Size: 39801

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

LSP Connector for Sublime Text

A Language Server Protocol connector for Sublime Text 3.

The project is in beta mode. Feedback or issue? Please email us at support@sourcegraph.com or file an issue.

Overview

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.

Operations supported

This connector currently supports:

Autocomplete, semantic symbol-based search, formatting utilities will soon be supported.

Languages 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.

Installation
Connector installation

Install the sublime-lsp connector for Sublime Text by cloning sublime-lsp repository into your Sublime Text 3 Packages folder:

macOS:

clone git@github.com:sourcegraph/sublime-lsp.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/sublime-lsp

Linux:

clone git@github.com:sourcegraph/sublime-lsp.git ~/.config/sublime-text-3/Packages/sublime-lsp

Windows:

%APPDATA%\Sublime Text 3\Packages"
clone https://github.com/sourcegraph/sublime-lsp
Go installation

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.

TypeScript/JavaScript installation

Install the TypeScript/JavaScript LSP server the following way:

rt JSTS_DIR=...
clone https://github.com/sourcegraph/javascript-typescript-langserver $JSTS_DIR
JSTS_DIR
install
_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.

Usage
Hover

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.

hover tooltips

Goto definition

Execute the Lsp: Goto definition command, and Sublime will jump to the definition of a symbol in your workspace.

goto def

Find all references

Execute the Lsp: Find all references command, and Sublime will open up a results pane with semantic references to the symbols within your project.

find all references

Diagnostics

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.

find all references

Troubleshooting
Make sure the langserver-go is installed

Run langserver-go -h in your command line. You should see a help menu.

Sublime Text 3 version check

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.

Remove Sublime Text 3 tooltips and Goto menu items

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
...

Using Sublime with LSP Connector
Open the command window

To open Sublime's command window and access LSP connector operations, just execute the following key combination:

Any search items starting with Language Server is provided by the LSP connector.

command bar access

Add right click menu options

By default, the sublime-lsp connector includes two options to your right click menu. Find local references and Explore code at cursor.

Change default keybindings

TBD

Support

Found a bug, want to request a feature, or want to help Sourcegraph build the global graph of code? Send us an email at hi@sourcegraph.com.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.