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

how to contribute extensions from another language server? #596

Closed
martinlippert opened this issue Nov 27, 2019 · 12 comments
Closed

how to contribute extensions from another language server? #596

martinlippert opened this issue Nov 27, 2019 · 12 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@martinlippert
Copy link
Contributor

I would like to write an extension to the lsp4xml language server that implements some Spring-specific things. The first issue I would like to tackle is to contribute a way to lookup an XSD namespace from the project classpath.

How do I contribute this extension to the lsp4xml language server? I know that I can implement the Java-based SPI, but how is my extension being found at runtime by the lsp4xml language server extension for VSCode or Eclipse, for example?

JDT.LS does something like dynamically looking up extensions and loading them into the OSGi runtime. Is something like that available for the lsp4xml language server, too?

@angelozerr
Copy link
Contributor

angelozerr commented Nov 27, 2019

@martinlippert I'm so happy that you create this issue!

but how is my extension being found at runtime by the lsp4xml language server extension for VSCode or Eclipse, for example?

You can find a very basic lsp4xml extension with completion in

For the moment it's not possible to communicate inside the completion participant with another Language Server because it requires to:

  • access to LanguageClient instance in completion participant
  • cast this LanguageClient instance in completion participant into the proper interface which adds a custom request (STSLanguageClient) (ex : ((STSLanguageClient)languageClient).searchSTS(...)
  • the cast to STSLanguageClient will work only when XMLServerLauncher will be the capability to add this STSLanguageClient dynamically when launcher is created.
  • on client side vscode-xml must give the capability to delegate the searchSTS request to the Spring Tools language client

But this requires microsoft/vscode-languageserver-node#526

I think vscode-xml could provides this binding features at the first step.

@BoykoAlex
Copy link
Contributor

Don't think this can implemented without XML LS and Spring Boot LS talking to each other. microsoft/vscode-languageserver-node#526 has been idle for some time now but I'd go with the command registration/execution approach.
In other words XML LS sends request to execute a command to the client. Client looks up a command (registered by Boot LS) and executes it on the Boot LS. The result is then sent as response via a few hops back to XML LS.
RE: STSLanguageClient... What if we add xml/executeClientCommand to the XmlLanguageClient? It'd be something rather generic, a request from server to client to execute a command (string) with parameters (any[]') and response just Object'. Don't think it'd be a problem adding handling in VSCode for the request above... Should be doable in lsp4e with a patch probably.
These are my thoughts about this for now. Am I overthinking this, missing or misunderstanding anything?

@angelozerr
Copy link
Contributor

These are my thoughts about this for now. Am I overthinking this, missing or misunderstanding anything?

If I understand correctly, you want to manage communication with command like vscode-java provides. I think we can start with this feature.

Have you the intention that Spring Boot vscode depends on vscode-xml ?

@martinlippert
Copy link
Contributor Author

@angelozerr Ideally I think we don't want the Spring Boot vscode extension to depend on the vscode-xml in a way that requires users to have both installed. I think the overall design here would be:

  • the Spring Boot vscode contributes an extension to the vscode-xml
  • if there is no vscode-xml installed, just nothing would happen here
  • if there is vscode-xml installed, our extension would be used by vscode-xml

In case vscode-xml is around, our extension would call out to the Spring Boot vscode extension via the command mechanism that Alex described above - which basically means (from an abstract point of view) that our vscode-xml extension would call out to the Spring Boot language server to get some information - and once it got the information back, proceed with its work (resolving namespaces in our concrete case).

The underlying problem for us here is that our namespace resolver implementation need to know the Java project context and the classpath of the project to lookup stuff (mappings and concrete XSD files). But the generic XML language server has no knowledge of that, therefore our namespace resolver would need to reach out to someone (the Spring Boot language server, in our case) to collect that information.

Another side note: our plan is to use the same extension for the XML language server in Eclipse as well as VSCode... :-)

@angelozerr
Copy link
Contributor

angelozerr commented Oct 2, 2020

@angelozerr Ideally I think we don't want the Spring Boot vscode extension to depend on the vscode-xml in a way that requires users to have both installed.

Sorry I don't understand, you mean that you have your own vscode-xml which starts XML Language Server LemMinx ? Why you want to do that?

The underlying problem for us here is that our namespace resolver implementation need to know the Java project context and the classpath of the project to lookup stuff (mappings and concrete XSD files). But the generic XML language server has no knowledge of that, therefore our namespace resolver would need to reach out to someone (the Spring Boot language server, in our case) to collect that information.

At first LemMinx provides URIResolverExtension API that you can implement and you can contribute it. Here an extension sample for resolving XML catalog namespace

If you expose a JDT LS command from Spring Boot LS which provides information for the Java classpath project, the XML Language Server could consume in your custom namespace resolver implemented by LemMinx URIResolverExtension, no?

I think it's shame to have 2 XML Language Server which will be started (on by vscode-xml and one by your vscode-xml) because we will have double XML parsing file. Or perhaps I don't understand correctly your idea?

@martinlippert
Copy link
Contributor Author

martinlippert commented Oct 2, 2020

Sorry I don't understand, you mean that you have your own vscode-xml which starts XML Language Server LemMinx ? Why you want to do that?
I think it's shame to have 2 XML Language Server which will be started (on by vscode-xml and one by your vscode-xml) because we will have double XML parsing file. Or perhaps I don't understand correctly your idea?

Nooooo.... :-)

I don't want to run a separate XML language server (by no means). The idea is to contribute an extension to the XML language server (as you described) and let the XML language server use that extension.

Let me clarify on the comment above about the "dependency":
If the user has the XML extension installed (in VSCode or Eclipse), we contribute our extension and enhance the namespace resolving. If the user does NOT have the XML extension installed, we do nothing. We just don't want to force users to install the XML extension if they instal the Spring Boot extension - like you could do with a dependency on the vscode extension level. Makes sense?

@angelozerr
Copy link
Contributor

Nooooo.... :-)

I don't want to run a separate XML language server (by no means). The idea is to contribute an extension to the XML language server (as you described) and let the XML language server use that extension.

Great!

Let me clarify on the comment above about the "dependency":
If the user has the XML extension installed (in VSCode or Eclipse), we contribute our extension and enhance the namespace resolving.

Ok we have the same idea :)

If the user does NOT have the XML extension installed, we do nothing.

It means that you will loose your namespace resolving feature?

We just don't want to force users to install the XML extension if they instal the Spring Boot extension

Is there any reason to do that? For the user it's transparent the vscode-xml installation will be done when you will install Spring Boot, no?

  • like you could do with a dependency on the vscode extension level. Makes sense?

Yes!

@BoykoAlex
Copy link
Contributor

Great thanks for the quick feedback. I'll go with the command registration approach for comm between XML and Boot LS. Once there is a working prototype the shape of the solution would be much clearer and we could collaborate on polishing it up :-)

@angelozerr
Copy link
Contributor

Great thanks for the quick feedback. I'll go with the command registration approach for comm between XML and Boot LS. Once there is a working prototype the shape of the solution would be much clearer and we could collaborate on polishing it up :-)

Great!

I think we should have a work on vscode-xml side too.

@angelozerr
Copy link
Contributor

@BoykoAlex I need this custom command support for our internal extension (referenced grammars which show referenced XSD, DTD in the outline). Have you the intention to provide a PR for this support or do you prefer I implement it?

Thanks for your feedback.

@BoykoAlex
Copy link
Contributor

BoykoAlex commented Oct 8, 2020

@angelozerr yes, I'll create a draft PR for this today. It'd definitely need corrections. The intention of the PR is to merely show stuff our Spring XML extension needs, then we can figure out perhaps how best to wrap it in some nice API. It is going to be a PR for the XML server and for WWD XML, haven't worked on the VSCode side yet (not worried about it) but planning to

@angelozerr
Copy link
Contributor

@angelozerr angelozerr added this to the 0.14.0 milestone Oct 13, 2020
@angelozerr angelozerr added the enhancement New feature or request label Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants