Skip to content
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

Support for diagnostics #12

Open
cotttho opened this issue Dec 6, 2024 · 5 comments
Open

Support for diagnostics #12

cotttho opened this issue Dec 6, 2024 · 5 comments

Comments

@cotttho
Copy link

cotttho commented Dec 6, 2024

What would it take to support diagnostics?

@themichaelusa
Copy link
Contributor

@cotttho Could you elaborate? Am working on a few nascent PRs right now - so I might be able to include your request if it's not too much heavy lifting.

@cotttho
Copy link
Author

cotttho commented Dec 10, 2024

I am interested in using multilspy to retrieve diagnostic information from different language servers, but the diagnostics LSP API is not currently supported.

@themichaelusa
Copy link
Contributor

Gotcha. I'll look into it sometime this week and get back to you.

@LakshyAAAgrawal
Copy link
Collaborator

LakshyAAAgrawal commented Dec 12, 2024

Hi @cotttho and @themichaelusa ,

I believe it should not be difficult to add support for diagnostics. Do you have a specific usecase in mind that you can contribute as a unittest?

multilspy internally uses a LanguageServerHandler (https://github.com/microsoft/multilspy/blob/main/src/multilspy/lsp_protocol_handler/server.py#L142) class, that supports the full LSP protocol (even the APIs not supported at the multilspy level). One hacky way to get diagnostics working (and this is actually how I got the first version of all currently supported multilspy apis to work), before we integrate it as a first-class API in multilspy is as follows:

  1. Create a multilspy lsp object and start the corresponding server that support diagnostics (for example Eclipse JDTLS)
lsp = LanguageServer.create(...)
async with lsp.start_server():
    result = await ...
  1. lsp.server is an object of type LanguageServerHandler that defines the send and notify methods, the 2 methods that clients use to communicate with the language server. Internally, multilspy uses the send and notify methods to invoke the LSP APIs. For example, the request_definition method of multilspy internally uses self.server.send.definition (
    response = await self.server.send.definition(
    ). Once you have a LanguageServer object with a running server (via start_server), you can invoke ALL lsp APIs simply by doing:
    result = await lsp.server.send.<API name like definition/references/completion etc>(<args to be passed>)
    
    In your case, you will invoke lsp.server.send.text_document_diagnostic or lsp.server.send.workspace_diagnostic (
    async def text_document_diagnostic(
    self, params: lsp_types.DocumentDiagnosticParams
    ) -> "lsp_types.DocumentDiagnosticReport":
    """The document diagnostic request definition.
    @since 3.17.0"""
    return await self.send_request("textDocument/diagnostic", params)
    async def workspace_diagnostic(
    self, params: lsp_types.WorkspaceDiagnosticParams
    ) -> "lsp_types.WorkspaceDiagnosticReport":
    """The workspace diagnostic request definition.
    @since 3.17.0"""
    return await self.send_request("workspace/diagnostic", params)
    ) with appropriate arguments (https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#documentDiagnosticParams or https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspaceDiagnosticParams).

Once you are able to get a version of diagnostic working with the underlying API, I would be glad if you could share your script, and we could implement first-class support for it in multilspy. I would be glad if you could actually PR this.

I would be glad to help with any part of the implementation process, or detail any more steps/help debug anything.

@LakshyAAAgrawal
Copy link
Collaborator

Another note: LSP supports diagnostics in 2 modes:

  1. The server notifys the client whenever there is a diagnostic.
  2. The client requests the server when it wants diagnostics

We can discuss what would be a better way and which to integrate into multilspy (both?). The second approach seems more closer to the rest of the APIs (request -> response), which is what I shared the steps above for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants