Giter Club home page Giter Club logo

lsp's Introduction

LSP

Like an IDE, except it's the good parts. Learn more.

TypeScript Server Example

Installation

Stable Version

Open the command palette and run Package Control: Install Package, then select LSP.

Development Version

Clone this repository into your Packages directory. Open the command palette and run Package Control: Satisfy Dependencies.

Getting started

Follow the installation steps for a specific language server.

Open a document supported by the language server. LSP should report the language server starting in the status bar.

See more information in the documentation ๐Ÿ“–.

Getting help

If you have any problems, see the troubleshooting guide for tips and known limitations. If the documentation cannot solve your problem, you can look for help in:

lsp's People

Contributors

amjadhd avatar ayoub-benali avatar braver avatar deathaxe avatar dependabot[bot] avatar dvcrn avatar frou avatar haferburg avatar htmue avatar husanjun avatar jfcherng avatar jgirardet avatar jwortmann avatar kronuz avatar ldap avatar loneboco avatar moodmosaic avatar munahaf avatar nikeee avatar olegsmelov avatar plinss avatar predragnikolic avatar randy3k avatar rapptz avatar rchl avatar rictic avatar rwols avatar themilkman avatar tomv564 avatar vogelsgesang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lsp's Issues

No client available for view if already open on ST startup

By default ST has set hotexit: true, which causes the previous session and all its open files to be restored the next time ST starts.

LSP does not create a client object for such views. Instead the following lines are displayed.

LSP: Config added: dotty 
LSP: Config added: clangd 
LSP: Config added: jsts 
LSP: Config added: rls 
LSP: Config added: pyls 
LSP: no clients found for window 2 
LSP: pyls not available for view C:\Apps\Sublime\Data\Packages\LSP\main.py in window 2 

The pyls is started as soon as the view is deactivated and activated again by minimizing and restoring ST window or switching to another view and return.

It looks like the issue may be triggered by a bug in ST core, which prevents the on_load and on_activated_async to be sent to already open views upon startup, but maybe LSP could lazily initialize lsp servers for open views in the plugin_loaded() hook.

[Feature request] Merge configurations?

Correct me if I'm wrong, but right now if you set a custom "clients" in preference, it overrides the default config rather than merging them together. Would it make sense if that configs are merged?

Expand variables in language server command setting

As described in #27, PHP's language server can be installed globally in the user's home, or local to the project.

It is a minor effort for the user to fill in the absolute path, but if we support ~ we can provide default or copy-paste-able configuration for more language servers.
Language servers installed per-project cannot be achieved unless we expand $project_path etc.

How to handle windows with multiple root folders?

The LSP package currently handles windows with multiple folders by finding a common prefix.

As discovered in #24, a common usage with Sublime workspaces is to link in whole trees of projects, perhaps even from multiple drives (e.g. C:\Users\Tom\Projects and D:\Work\)

For this scenario, it is increasingly unlikely that we can find a common prefix to give the language server as rootUri.

Looking at the language server protocol, the workspace concept (of which there is only one in a language server process) offers these actions:

workspace/symbols (would you really want to execute this across both drives ?) workspace/didChangeConfiguration (configuration is likely to be project-specific, if anything)

An improvement would be to create an LSP instance per window.folders().

Users who choose to mount the parent folder of multiple projects will have to accept that:

  • workspace symbol listing is for projects
  • The LSP package will not be able to help with per-project configuration.

Support window/showMessage(Request)

As seen in the ocaml language server (#57), there is great value in language servers telling the user how to fix configuration etc. The language server protocol exposes a notification and a request from the server:

showMessage: show in status bar + allow user to specify getting a message box
showMessageRequest (with actions to respond with?): quick panel?

Missing dependencies.json

As you use mdpopups package, you should add a dependencies.json to your package to let Package Control install it automatically if not yet available.

Needs more documentation

To lift this plugin off the ground it should have way more documentation in the readme:

  1. "What does it do and why would you care?" section (Yes, I see that it lists the features but it's somewhat dry).
  2. Explain the big picture: client-server thing, this plugin is only the client, can talk to any server respecting the LSP.
  3. Give some practical examples to get started with popular languages.

Fix Format Document

May affect rename as well. (any logic applying workspace edits)

Repro: (in clangd) choose Format document, receive chopped up file.

Unable to make this work with ocaml-language-server

Hello! So glad to see LSP in ST. The OCaml/Reason language server is pretty complete: https://github.com/freebroccolo/ocaml-language-server

I've tried the following config:

{
  "clients": {
    "reason": {
      "command": ["ocaml-language-server", "--stdio"],
      "scopes": ["source.ml", "source.mli", "source.re", "source.rei"],
      "syntaxes": ["Packages/User/sublime-reason/Reason.tmLanguage"],
      "languageId": "reason"
    }
  }
}

This config didn't seem to work. It says LSP: config not available for view path/to/test.re, though the scope is definitely correctly specified.

Support resolving completion items

Since javascript-typescript-langserver has switched to providing much less detail in CompletionItems, we now need to resolve to get the snippet support back.

How to split main.py into multiple modules?

main.py is pretty full.

I have two concerns about splitting it up:

Where should we start? How small should the modules be?

Example for Commands:

  • create commands.py, -or-
  • split each command into commands/SomeCommand.py

Initialized is fired too late?

LSP logs initialized after the first textDocument/didOpen goes out.
The spec says it should be sent:

after the client received the result of the initialize request but before the client is sending any other request or notification to the server

It is possible the logging is out-of-order, need to investigate.

LSP: starting ['pyls']
LSP: request 1: initialize 
LSP: client registered for window 2 {'pyls': <LSP.main.Client object at 0x106a7a2d0>}
LSP: got json:  {"result":{"capabilities":{"definitionProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"hoverProvider":true,"documentSymbolProvider":true,"executeCommandProvider":{"commands":[]}
LSP: notify: textDocument/didOpen
LSP: notify: initialized
LSP: got json:  {"method"

PHP supports

Hi @tomv564 , one thing I really want to see is LSP can work with PHP.
Maybe I was doing something wrong, but I got this from console panel after I setup the php-language-server

LSP: starting in /Users/DjangoWong/Workspace/freight-x 
LSP: starting ['php', '~/.composer/vendor/felixfbecker/language-server/bin/php-language-server.php'] 
LSP: client registered for window 2 {'phplsp': <LSP.main.Client object at 0x10f636f90>} 
LSP: LSP: LSP stdout process ended.LSP stderr process ended.  

And this is my lsp settings:

"clients": {
	"phplsp": {
		"command": ["php", "~/.composer/vendor/felixfbecker/language-server/bin/php-language-server.php"],
		"scopes": ["source.php"],
		"syntaxes": ["Packages/PHP/PHP.sublime-syntax"],
		"languageId": "php"
	},
},

btw, Im using ST3142 and php7 on MacOS sierra 10.12.6

Thanks

A universal diagnostics panel for LSP and SublimeLinter

Shortly before I found the LSP package, I developed another ST package which provides a diagnostics panel for SublimeLinter (see SublimeLinter-Dashboard; the PR for being managed by package control is still pending).

Obviously, the diagnostics panel of my package is very similar to the one provided by the LSP package. I'm not too sure about the exact differences. The LSP's highlighting/formatting looks better, however, it provides no keyboard shortcuts within the panel as far as I can see.

I think it would be nice to have one universal diagnostics view which is capable of showing errors and warnings originating from compilers/linters/language servers.
One approach for that would be to have a separate diagnostics panel package, which is responsible for rendering. Packages like SublimeLinter and ST-LSP could push errors/warnings (including click handlers and additional information) for each view to this package.

What do you think about this approach? Or do you think in the long run, linters should be implemented using the language server protocol?

I would be happy to work together for such an unified diagnostics panel.

Non-active but visible view is not opened when restarting sublime

Follow-up to #18.
When re-opening sublime with open documents in more than 1 group (split), only the active group's document is opened on the language server. The document in the non-active group is missing diagnostics until the user 'activates' the view by clicking on it.

phantoms cannot be dismissed / this feedback style too obtrusive

I tried this on a python project that has a lot of pycodestyle errors (indentation mostly). While perhaps I should do something about those in the first place, this makes it pretty hard to work with (and pretty hard to do something about the errors ๐Ÿ˜‰) :

screen shot 2017-08-19 at 12 20 19

Sublime's standard build result phantoms can be dismissed, and then cycled through with next_result and prev_result.

Showing unrequested feedback using phantoms is really obtrusive. All code has to shift to make place for the phantoms, which makes for a really bumpy ride if there is more than one phantom. Pretty much unusable.

bumpy-ride

I would suggest using linter-style (squiggly underline and/or gutter icons) feedback during editing, and then display the phantoms using a command. Perhaps the current behaviour should be optional, but it's easy enough to add a trigger for a "show phantoms" command. I definitely don't think it should be the default behaviour.

toplevel completions are ignored

The CompletionHandler drops all completions from the language server, if the cursor is not located directly after a completion character.

class CompletionHandler(sublime_plugin.EventListener):
   
    ...

    def on_query_completions(self, view, prefix, locations):
        ...
                 if prev_char not in autocomplete_triggers:
                    return None

This prevents toplevel completions from being displayed. Jedi as an example, provides a list of all available modules after the import keyword. Those completions are filtered at the moment.

Instead of filtering I'd rather suggest to use the completion character published by the language server to dynamically create an auto-completion trigger for the view. Accessors like -> could be added as > and the on_query_completions could check for the preceding - to decide whether to provide completions or not.

[Feature request] Override ST's default goto definition?

I was wondering why ST's Goto definition didn't work. I didn't get that LSP uses its own system and doesn't plug into ST's. Would it be possible for Goto definition to first consult LSP, and if a definition isn't found, fall back to the default string-based behavior?

Disable Sublime Text's own hovers if LSP provides feature

As suggested by @deathaxe, Sublime's built-in hovers will likely flash on-screen before LSP's hovers pop up.

I've seen some packages provide instructions to the user on adding show_definitions: false to syntax-specific settings.

We could also set show_definitions to false programmatically per view once LSP has loaded, or perhaps there is another clever way to suppress sublime's hover until we've tried the language service?

get_project_path() incorrectly determines path

If you have multiple sibling directories in a workspace with common prefix characters, it will incorrectly use a partial path for this.

I have two directories open, which are ~/Projects/example1 and ~/Projects/example2. os.path.commonprefix() will hence return ~/Projects/example, which is not a directory that exists. (The Python docs note that os.path.commonpath() should be used instead.)

This approach is generally problematic anyway. I have two subdirectories deep inside a common directory, and even without the partial filename problem, this is still problematic for me as it causes a lot more files than I care about to be indexed. This causes the initial parsing to take roughly forever.

VS Code is currently working on adding multi-root support (microsoft/vscode#28344), so I suspect they'll add support to the Language Server protocol at some point. The current behaviour in the beta is just to index the first directory in the project. IMO, this is the best behaviour until the protocol actually supports multi-root.

Diagnostics panel flickers constantly

When the diagnostics panel is open while you're typing, it appears to redraw multiple times per change, which a) is very distracting, and b) presumably isn't intentional.

Here's what happens when I type a single character:

lsp-diag-flicker

This is redrawing a lot considering there was a single character changed. Viewing the GIF frame-by-frame shows the redraws (this was recorded at 60fps).

Not sure if this is a problem with the language server I'm using (PHP) or with the plugin, but I suspect it's the plugin. Potentially a race condition? (Haven't debugged it yet.)

Pre-request code actions for visible diagnostics?

As a follow-up issue to #10, it would be great to query the language server if code actions are available before showing it in the diagnostic popups/phantoms.

Need to try out how we can restrict the amount of requests being sent when a document full of diagnostics is being opened, edited or scrolled through.

Consistent/configurable display of alerts

Some considerations after adding a "no code actions" popup in #10:

  • status_message is used for "find references" and "go to definition" cases, show_popup for code actions. This should be consistent?
  • The popup is a good default as it's really visible, perhaps the user can opt to only see status_message instead via settings?
  • Placement of the popup can be a bit off, especially when clicking Code Actions links in hovers/phantoms.

Priorize or combine diagnostics and symbol hovers

When hovering over a symbol with a diagnostic, the diagnostic hover usually is displayed first, but can be quickly replaced when the hover info arrives.

Perhaps diagnostics should always win, and a command could be added to trigger the hover manually?
Combining the two hovers is probably harder to do in a reliable/maintainable way.
Other options?

Navigation from diagnostics panel to error location in view fails

By double clicking into the diagnostics output panel, it is / seems intended to be able to navigate to the error location in the file. The view containing the file should be focused and scrolls to the error.

Didn't find the handler for this action right now. Maybe it is a default behavior of ST?

The issue with this functionality is - double clicking opens a new empty view instead, because the file path being used to find the view misses the drive letter.

screenshot

The reason is a wrong translation of the uri to a path relative to the project root. The following function assumes the common prefix of all folders in the sidebar to be this project root. This is wrong. You may add folders of any location to the sidebar and group them together as a single project. Therefore each view needs its own project root which is represented by exactly one element of window.folders().

def get_project_path(window: sublime.Window) -> 'Optional[str]':
    """
    Returns the common root of all open folders in the window
    """
    if len(window.folders()):
        folder_paths = window.folders()
        return os.path.commonprefix(folder_paths)
    else:
        debug("Couldn't determine project directory")
        return None

I temporarily ommited translation to relative path in update_diagnostics_panel(window), which fixes the navigation issue.

screenshot

There are 2 options:

  1. always show absolute paths in the output panels
  2. fix translation to relative paths (my favorite)

Fix package issues before submitting

From st_package_reviewer:

## Report for  ########################################

Reporting 7 failures:
- '.sublime-workspace' files contain session data and should never be submitted to version control
    File: LSP.sublime-workspace
- The binding ['super+alt+r'] unconditionally overrides a default binding
    File: Keymaps/Default (OSX).sublime-keymap
- The binding ['f12'] unconditionally overrides a default binding
    File: Keymaps/Default (OSX).sublime-keymap
- The binding ['ctrl+shift+m'] unconditionally overrides a default binding
    File: Keymaps/Default (Linux).sublime-keymap
- The binding ['f12'] unconditionally overrides a default binding
    File: Keymaps/Default (Linux).sublime-keymap
- The binding ['ctrl+shift+m'] unconditionally overrides a default binding
    File: Keymaps/Default (Windows).sublime-keymap
- The binding ['f12'] unconditionally overrides a default binding
    File: Keymaps/Default (Windows).sublime-keymap

Reporting 6 warnings:
- Found multiple command prefixes: Apply, Clear, Code, Document, Format, Restart, Show, Symbol. Consider using one single prefix so as to not clutter the command namespace.
- '.sublime-syntax' support has been added in build 3092 and there is no '.tmLanguage' fallback file
    File: Syntaxes/Diagnostics.sublime-syntax
- '.sublime-syntax' support has been added in build 3092 and there is no '.tmLanguage' fallback file
    File: Syntaxes/References.sublime-syntax
- The binding ['('] is also defined in default bindings but is masked with a 'context'
    File: Keymaps/Default (OSX).sublime-keymap
- The binding ['('] is also defined in default bindings but is masked with a 'context'
    File: Keymaps/Default (Linux).sublime-keymap
- The binding ['('] is also defined in default bindings but is masked with a 'context'
    File: Keymaps/Default (Windows).sublime-keymap


For more details on the report messages (for example how to resolve them), go to:
https://github.com/packagecontrol/py_package_reviewer/wiki

Only show diagnostic panel when uri matches current view

In Julia server, it starts by linting all files at the current directory. It may make sense to only show the panel when the uri of notification matches the current view. Otherwise, it will popup and refresh the panel multiple times.

Release 0.2

To do:

  • sweep through issues to produce changelog + list contributors
  • document new settings
  • create 0.2 entry in package control messages
  • tag release

No syntax highlighting in popups

Hi,

First of all, great work on this packageโ€”I'm already getting quite a bit of use out of it.

I have one question, though: unlike in the README's screenshot, the hover popups often seem to lack some combination of syntax highlighting and formatting. Here are a few examples:

screen shot 2017-08-29 at 9 10 06 am no-syntax
pyls popup without code formatting or syntax highlighting. go-langserver popup without syntax highlighting.

Is this intended?

Thanks!

Add options for phantom creation/refreshing/dismissal

An outcome of the discussion in #23:

  • A "Create Phantoms" command that creates phantoms from a diagnostics snapshot
  • We restore the close button on the phantoms so you can dismiss them individually.
  • A "Dismiss Phantoms" command that gets rid of all of them.

The current behaviour could then be configured as:
"create_diagnostics_phantoms_on_save": true
"dismiss_diagnostics_phantoms_on_dirty": true

Occasional deadlooks freeze ST on Windows

I recently have experienced ST to freeze with little CPU usage while working in a python file which is attached to python-language-server 0.4.1 using LSP package.

All other language supporting packages are disabled after installing LSP some days ago.

It looks like there are some deadlocks somewhere. Situation seemed to become worse, when I tried to disable debug logging which pollutes the console.

Not quite sure how to find out how it is triggered - maybe it is caused by on_hover event.

Windows 10 x64 / ST 4142 x64

[Feature request] ignore certain lint errors

Some language servers report also code styling warnings and some of the warnings are over-killed.
Besides launching the language server with extra arguments (and some servers do not take arguments at all), It would be nice to ignore certain lint errors at Sublime Text level.

Show tooltip even when no hover information could be found

Usually, when hovering over code a tooltip with some information is provided by the server. However, the server can also send "nothing" back (most simple example would be an empty line). In this case, LSP doesn't show a tooltip at all, which can be a bit annoying since it's not clear:

  • if the hovering didn't work correctly or
  • if LSP is still waiting for a reply or
  • if there is simply no hover information available

To cut a long story short: I'd suggest to always show a tooltip on hover. If the server didn't provide information, then it could just say so ("No information available" or similar).

Agree? I could do a PR if you want.

Format Document on save option

Similar to Clang Format, it'd be nice to have a setting in the settings (false by default maybe) called "format_on_save" that will apply the "Format Document" action when the view is saved (on_pre_save)

EDIT: Since it's probably an async option you'd have to bake in some way to "wait" for the server to give a response before actually returning from EventListener.on_pre_save. I'll stop thinking about details now.

Why calling create_output_panel twice?

Why do you call window.create_output_panel() after applying settings again? It is the first time, I see something like that and did not realize any issue with not doing so. I am running ST 4142. Is it a workaround for earlier builts?

def create_references_panel(window: sublime.Window):
    panel = window.create_output_panel("references")
    base_dir = get_project_path(window)
    panel.settings().set("result_file_regex",
                         r"^\s+(\S*)\s+([0-9]+):?([0-9]+)$")
    panel.settings().set("result_base_dir", base_dir)
    panel.settings().set("line_numbers", False)
    panel.assign_syntax("Packages/" + PLUGIN_NAME +
                        "/Syntaxes/References.sublime-syntax")

    # call a second time to apply settings   ??? really needed ???
    return window.create_output_panel("references")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.