Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you publish diagnostics with this library? #11

Closed
tonyalaribe opened this issue Jun 25, 2022 · 4 comments
Closed

How do you publish diagnostics with this library? #11

tonyalaribe opened this issue Jun 25, 2022 · 4 comments

Comments

@tonyalaribe
Copy link

Hi, first of all, thanks for the tremendous amount of work you put into this library.

I'm implementing an LSP for a doctest library which I wrote (https://github.com/apitoolkit/doctests), and the way it should work is such that a user can add golang expressions into their comments, and they can execute those expressions like an inline repl. But the documentation of LSPs has been tough so far. Including on the official lsp spec website. So maybe you can help me better.

I've been able to implement this functionality in 2 ways already, but each way doesn't completely give me what I would like or expect.

  1. Via codelens

image

I implement the TextDocumentCodeLens which triggers code commands. But the problem is that in the WorkspaceExecuteCommand handler, the return type is just an interface, so I'm completely clueless about how to update the document i'm in like with code actions. So I end up editing the file on disk in the execute command function, but then the user has to reload the file from disk to see the changes i made, or risk making more changes and overwritting the files on disk.

Is there a type/data that i can return from executeCommand, to make it edit the current text document instead of by passing the editor to directly edit the file on disk?

  1. I've also been able to implement the functionality via code actions, and with code actions I can return the protocol.Edit values, where i define a range in the document and it's new text content. This works very smoothly with no issues. The problem is that, unlike with code lenses, I don't get any visual cue telling me that the comment line can be evaluated or refreshed. So I figured maybe we need to manually publish the diagnostics, but I have been unable to figure out how to trigger publishing diagnostics with this library as well. Could you help? Or just point me to resources?
@tliron
Copy link
Owner

tliron commented Jun 25, 2022

The documentation simply says that you can return a result and an error, the latter being "code and message", which is a little too thin. I interpret this to imply that different implementations might handle the "error" differently...

@tonyalaribe
Copy link
Author

tonyalaribe commented Jun 25, 2022 via email

@tliron
Copy link
Owner

tliron commented Jun 26, 2022

I have never done so myself. Perhaps other users can chime in with advice?

@mickael-menu
Copy link
Contributor

mickael-menu commented Jun 26, 2022

I implemented diagnostics with glsp, you can take a look here:
https://github.com/mickael-menu/zk/blob/68e6b70eaefdf8344065fcec39d5419dc80d6a02/internal/adapter/lsp/server.go#L556

I refresh them when receiving TextDocumentDidOpen and TextDocumentDidChange, with a custom throttle of one second with TextDocumentDidChange, to wait for the user to be idle before refreshing the diagnostics (this is the delay bool parameter with NeedsRefreshDiagnostics).

It looks like this in Neovim:

image

I didn't use the code parameter but the message and severity ones.

Repository owner locked and limited conversation to collaborators Jun 26, 2022
@tliron tliron converted this issue into discussion #12 Jun 26, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants