martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.26k stars 259 forks source link

Feature Request: lsp ( Language Server Protocol) client for vis #853

Closed varbhat closed 3 years ago

varbhat commented 4 years ago

The Language Server protocol is used between a tool (the client) and a language smartness provider (the server) to integrate features like auto complete, go to definition, find all references and alike into the tool .

Read more here -> https://langserver.org/

I would like to request lsp support for vis. These are possibilities regarding implementation of lsp client for vis. 1) lsp client as part of vis core triggered by set options ( set lspc on maybe?) 2) lsp client implemented as addon implemented by lua APIs.

I prefer 1st one because it will be fastest/less-energy-consuming. I think that lsp is desirable to have in vis.

See: 1) https://github.com/fhs/acme-lsp (Written in go) 2) https://github.com/ul/kak-lsp (Written in rust)

wizhi commented 3 years ago

Any specific reason why this was closed?

I do see @martanne and others acknowledge the value of LSP in #547, but other than that I can't find much on the subject.

Before I open a new issue on this, do you have any specific reasoning for closing this @varbhat?

varbhat commented 3 years ago

@Wizhi There is no specific reason this was closed.

fischerling commented 3 years ago

Maybe a asynchronous Lua LSP client could be implemented using #675.

fischerling commented 3 years ago

I started a pure Lua prototype using the vis:communicate patch from #675. The code can be found at https://github.com/fischerling/vis-lspc
https://gitlab.com/muhq/vis-lspc. Currently it does not support the textDocument/didChange method required by LSP text synchroniaztion. This makes vis-lspc hardly usable. But if we can figure out how to implement change notifications with vis I think this has potential.

Completions and goto declaration/definition are somewhat working. I tested it only with clangd in a medium size c++ project.

Any feedback, UX/implementation ideas or contributions are welcome :)

erf commented 3 years ago

@fischerling maybe an idea is to listen to the win_highlight event and then check if the file content was changed? (since there is no Lua API for detecting document changes in vis per now)

fischerling commented 3 years ago

@fischerling maybe an idea is to listen to the win_highlight event and then check if the file content was changed? (since there is no Lua API for detecting document changes in vis per now)

This is what I do in vis-spellcheck but there I only have to check the view_port to update the visible highlighting not the entire file. And how would we detect modification? Hash the entire file on each highlight event?

The only two solutions I can see are either native FILE_CHANGED events (which are not super trivially to implement) or we send a didChange notification with the whole file before issuing other method calls.

I think I try the second approach and see if it is a somewhat acceptable solution.

fischerling commented 3 years ago

So I actually implemented the textDocument/didChange notification before any other textDocument method approach.

Now vis-lspc should be in a more or less usable state.

Let me know your opinions, language servers you use, experiences, ...

wizhi commented 3 years ago

That's great @fischerling!

I've not gotten too into vis yet, so I'm afraid I can't help too much, but I'll give it go as soon as I get the chance to.

fischerling commented 3 years ago

Sorry to spam this issue!

I completed v0.1.0 which does everything I want from a LSP client:

  1. completions
  2. navigation: goto references, declarations, definition and go back (this replaces vis-ctags for me)
  3. comfortably select a choice when multiple choices are available using fzf
  4. automatically starting clangd, and registering the files I have open
  5. It works with clangd

I am not planning to spend much more time on it, except fixing bugs I encounter. If you want anything from vis-lspc what it currently does not support (new language servers, new LSP methods, diagnostics, LSP commands, space rockets, ...) you have to either implement it yourself or reach out to me.

tonchis commented 3 years ago

@fischerling Good morning/afternoon! I was also looking for an LSP client here in vis, and was wondering if you can share the work you did. A bit more context, I'm about to dive in on implementing LSP messages for a language and would like to see it working with vis.

Thanks!

fischerling commented 3 years ago

@fischerling Good morning/afternoon! I was also looking for an LSP client here in vis, and was wondering if you can share the work you did. A bit more context, I'm about to dive in on implementing LSP messages for a language and would like to see it working with vis.

Thanks!

Hey @tonchis,

You can look at vis-lspc there is everything I did so far. Short overview of what is implemented:

All features and the whole vis-lspc is crippled in its UX since we have no good way to detect changes to a file from Lua. Therefore we have to send the whole file before each LSP method invocation. This approach has multiple drawbacks:

Everything else is not implemented.

I would love to hear from you and your plans to improve LSP support for all vis users :)

Let us move further questions/discussion into the vis-lspc repo to prevent spam in the vis repo.

mcepl commented 2 years ago

@fischerling I just want to say that vis-lspc is awesome! Thank you.