Sublime Forum

LSP: Universal language server plugin

#1

Time to share my hobby project, which I’ve been using for javascript/typescript development for the last few months.

It aims to expose features from any LSP-based language server in a consistent manner.
I’ve tested it on Windows and OS-X and against a few servers, but I would love your comments and feedback before I try to publish it.

It can be manually installed from https://github.com/tomv564/LSP, and some setup instructions are at http://lsp.readthedocs.io/

16 Likes

Autocomplete C
#2

Where do I specify the compilation database for clangd?

0 Likes

#3

This would be a good question for the clang developer mailing list, as mentioned at the bottom of https://clang.llvm.org/extra/clangd.html

My guess is it searches in a source file’s current and parent directories, see https://github.com/llvm-mirror/clang-tools-extra/blob/master/clangd/GlobalCompilationDatabase.cpp#L74-L89

0 Likes

#4

Very interested in this. It could be an important package for Sublime!

Could you please give an example of complete setup for normal JavaScript, for those of us not using TypeScript at all?

It’s also not clear what we’re supposed to do with those auto_complete_triggers JSON fragments shown in the docs.

0 Likes

#5

Thank you. After I’ve put compile_commands.json file at the root of my project and added it to my gitignore, the clang daemon seems to be working.

I have to say: nice job on starting this plugin. I’ll give you some suggestions from the perspective of the c-family of languages.

  1. Try to do linting a-la SublimeLinter style, instead of opening an output panel with errors/warnings.
  2. Completion results need work. They are not snippet-like. For instance, a method/function completion should present me a snippet where I can tab through the parameters of the function.
  3. Completions results need work part 2. Private methods are also presented in places where they should not. I guess this is more of a clang issue.
  4. Header files are usually not part of the compilation database. As a result, I get completely wrong errors/warnings in header files, and a lot of them. I need a way to “exclude” certain file extensions from being consumed by clangd.

I really like the goto symbol definition functionality.

The format document functionality seems to be broken?

0 Likes

#6

I’ve learned that snippet-like completions are also a clangd issue, so forget about points 2 and 3.

0 Likes

#7

Awesome that you got it working!

Also appreciate the suggestions:

  1. Created an issue for this: https://github.com/tomv564/LSP/issues/1
  2. Supported by this plugin, but not yet by clangd.
  3. Could be a clang issue, could also be LSP falling back to sublime’s “smart” syntax-based suggestions.
  4. Clangd has recently added support for receiving extra compiler flags when you open a document. This is unfortunately not part of the LSP protocol, but I created an issue here: https://github.com/tomv564/LSP/issues/2
0 Likes

#8

Thanks for checking it out!

The client settings for plain javascript were missing - I have just added them in the default jsts configuration. Can update and try it again?

LSP uses both the full syntax name and scopes to detect relevant documents, this will probably need to change to something less brittle.

The auto_complete_triggers are left up to the user to add to Sublime’s syntax-specific settings.

In the short term LSP could include some defaults for popular languages, I created an issue for making this part of the setup easy.

1 Like

#9

Had just a very short look into it.

The python language server complains about the document not being within the workspace. May this caused by \\ being used on windows? Maybe some path translation is required?

pip install python-language-server

python 3.5.2 (windows 10 x64)

LSP: (stderr):  Traceback (most recent call last): 
LSP: (stderr):  File "c:\apps\python\lib\site-packages\jsonrpc\manager.py", line 108, in _get_responses 
LSP: (stderr):  result = method(*request.args, **request.kwargs) 
LSP: (stderr):  File "c:\apps\python\lib\site-packages\pyls\python_ls.py", line 83, in m_text_document__did_close 
LSP: (stderr):  self.workspace.rm_document(textDocument['uri']) 
LSP: (stderr):  File "c:\apps\python\lib\site-packages\pyls\workspace.py", line 31, in rm_document 
LSP: (stderr):  self._docs.pop(doc_uri) 
LSP: (stderr):  KeyError: 'file:///C:/Apps/Sublime/Data/Packages/CNC%20Sinumerik%20840D/plugin.py' 
LSP: notify: textDocument/didOpen 
LSP: (stderr):  2017-08-15 22:58:50,653 UTC - ERROR - jsonrpc.manager - API Exception: {'message': 'Document file:///C:/Apps/Sublime/Data/Packages/LSP/main.py not in workspace \\Apps\\Sublime\\Data\\Packages', 'type': 'ValueError', 'args': ('Document file:///C:/Apps/Sublime/Data/Packages/LSP/main.py not in workspace \\Apps\\Sublime\\Data\\Packages',)} 
LSP: (stderr):  Traceback (most recent call last): 
LSP: (stderr):  File "c:\apps\python\lib\site-packages\jsonrpc\manager.py", line 108, in _get_responses 
LSP: (stderr):  result = method(*request.args, **request.kwargs) 
LSP: (stderr):  File "c:\apps\python\lib\site-packages\pyls\python_ls.py", line 86, in m_text_document__did_open 
LSP: (stderr):  self.workspace.put_document(textDocument['uri'], textDocument['text']) 
LSP: (stderr):  File "c:\apps\python\lib\site-packages\pyls\workspace.py", line 27, in put_document 
LSP: (stderr):  self._check_in_workspace(doc_uri) 
LSP: (stderr):  File "c:\apps\python\lib\site-packages\pyls\workspace.py", line 69, in _check_in_workspace 
LSP: (stderr):  raise ValueError("Document %s not in workspace %s" % (doc_uri, self.root)) 
LSP: (stderr):  ValueError: Document file:///C:/Apps/Sublime/Data/Packages/LSP/main.py not in workspace \Apps\Sublime\Data\Packages 
0 Likes

#10

It looks like you have an older version of python-language-service installed, as _check_in_workspace disappeared in the (latest) release 0.4.1. Could you update and try again?

1 Like

#11

I quickly called pip install without -U flag yesterday, but wasn’t aware of it not to call an upgrade of existing packages.

Works like a charm now.

One tip: You might want to disable sublime’s default "show_definitions" setting for views handled by the LSP in order to avoid popup fighting.

I am really happy to see this plugin. I was looking for some approaches of language servers for ST again and again. It will enable ST to support nearly any language in the future without the need to create dedicated language packages for ST. Really cool.

0 Likes

#12

I tried hooking up Go with https://github.com/sourcegraph/go-langserver

Find Symbol References and Go to Symbol Definition work fairly well. Though, the autocompletion is flakey (especially non-stdlib) and the go-langserver process is chewing major CPU!

0 Likes

#13

@tomv564 The commands offered in the right-click menu seem like they should be based on where the mouse cursor is rather than where the text input caret is

0 Likes

#14

Glad you like it, agree about show_definitions (created an issue: https://github.com/tomv564/LSP/issues/9)

About dedicated language packages, they are often impressively complete and specialised. I hope we can get “good enough” language support with a consistent user experience with LSP, instead of covering all the nice-to-haves/quirks of each language.

0 Likes

#15

How does this differ from https://github.com/sourcegraph/sublime-lsp?

0 Likes

#16

Having to primary-click before opening the context menu was always a major annoyance.

It should be fixed now, along with the Code Actions context menu item.

Thanks for the feedback!

1 Like

#17

Sublime-lsp is a fork of Microsoft’s (excellent, IMO) Typescript plugin. It was a clever way to get a polished package up and running quickly, but there is a lot of Typescript baggage left in the implementation.

By now, I believe LSP has a more complete implementation of the LSP protocol, and has been tested against more language servers.

There appears to be little effort going into sublime-lsp from sourcegraph or other volunteers since Nov 2016.

1 Like

#18

Great work! I’ll check it out soon with PHP, Python and JavaScript.

In the mean time, I’ve created a pull request to list it on the LSP page.

0 Likes

#19

Awesome, thanks for submitting it there!
I haven’t tried the PHP language server yet, curious how it works!

0 Likes

#20

Should I replace https://github.com/Microsoft/TypeScript-Sublime-Plugin with this plugin?

0 Likes