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

Provide a Language Server for bnd instructions #5833

Closed
laeubi opened this issue Oct 21, 2023 · 22 comments
Closed

Provide a Language Server for bnd instructions #5833

laeubi opened this issue Oct 21, 2023 · 22 comments

Comments

@laeubi
Copy link
Contributor

laeubi commented Oct 21, 2023

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.

Like discussed on EclipseCon2023 BND instructions seem very well suited to be provided as a LSP so it can be used in an IDE agnostic way.

For Eclipse there is https://github.com/eclipse/lsp4e to easily integrate such servers.

FYI @maho7791 @juergen-albert @stbischof ...

@mickaelistria can you give some advice here how to best start using lsp4j?

@mickaelistria
Copy link

I think the current documentation in LSP4J ( https://github.com/eclipse-lsp4j/lsp4j/blob/main/documentation/README.md ) already gives good advice. I suggest you get started from there, and if you have further questions, you may try opening issues against LSP4J to ask for details.

@pkriens
Copy link
Member

pkriens commented Oct 25, 2023

I did some work in this a couple of years ago. I maintain a LSP in the Alloys projects and it was easier than I thought. Although I was highly disappointed how many functions still required client side code.

There is a Red Hat project that uses LSP for Gradle + Maven. Seeing it was OSGi based I thought it would be easy to integrate bnd support there. I think this would still be a very valid approach but the code base, based on Maven, did not build out of the box and I could not get it to work quickly. They do not have some nice extension mechanism like services that I could see. However, combining effort with this would imho be the best approach.

If bnd(tools) has any future, then I think it would be in this direction. I am interested in pursuing this further if some other people are interested.

@laeubi
Copy link
Contributor Author

laeubi commented Oct 25, 2023

@pkriens I think a standalone LanguageServer would be sufficient here, I would expect it to have similar features like current BNDEditor but still things can be made on top of this on clientside so to summarize:

  • Autocompletion works for all known bnd instructions
  • Syntax highlight
  • Some error checking e.g. invalid values used for an instruction

@maho7791
Copy link
Contributor

Hi Peter, thanks for this hint. We currently trying different approaches with the LSP and wanna start something within next year. Guido is already trying to get firm with all that stuff. We are really interested to get something work in that direction

@laeubi
Copy link
Contributor Author

laeubi commented Oct 25, 2023

I think the current documentation in LSP4J (https://github.com/eclipse-lsp4j/lsp4j/blob/main/documentation/README.md ) already gives good advice.

@mickaelistria What I'm missing a bit is how to get a minimal working example e.g having a document with just for example one keyword ... last time I played around with LS it was quite hard to get something basic working ...

@pkriens
Copy link
Member

pkriens commented Oct 25, 2023

This is a very minimal LS for Alloy made specifically for Alloy: https://github.com/AlloyTools/org.alloytools.alloy/tree/master/org.alloytools.alloy.lsp It works like a charm on VS Code but does require a lot of client side code.

I once tried to quickly change it for bnd but Eclipse started to force me to do all kinds of Eclipse specific extension points and the Eclipse LSP client wasn't, I recall, overly impressive. I think Vogella has a tutorial on LSP.

We could setup a meeting to have a short discussion. It might be related to any PDE efforts. An LSP approach would have a huge number of advantages.

@pkriens
Copy link
Member

pkriens commented Oct 25, 2023

@pkriens I think a standalone LanguageServer would be sufficient here, I would expect it to have similar features like current BNDEditor but still things can be made on top of this on clientside so to summarize:

I do not think it would harm to see if any code could also be made to run in the Red Hat LSP. From what I know of it, that shouldn't be too hard.

@maho7791
Copy link
Contributor

@pkriens
Copy link
Member

pkriens commented Oct 25, 2023

@pkriens
Copy link
Member

pkriens commented Oct 25, 2023

If we get some active interest & commitments to work on this I suggest we move this work to a branch & a PR?

@laeubi
Copy link
Contributor Author

laeubi commented Oct 25, 2023

If we get some active interest & commitments to work on this I suggest we move this work to a branch & a PR?

I'll probably do some prototyping the next days...

@mickaelistria
Copy link

@laeubi

LanguageServer server = new LanguageServer() {
    //...
    @Override
    public TextDocumentService getTextDocumentService() {
       return new TextDocumentService() {
           //...
          @Override
          public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(CompletionParams position) {
             return CompletableFuture.completedFuture(Either.forLeft(List.of(new CompletionItem("keyword"));
       }
};
Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(server, System.in, System.out);

Just looking for createServerLauncher on GitHub should give some example. I used to show https://github.com/mickaelistria/eclipse-languageserver-demo/blob/master/Le LanguageServer de Chamrousse/ in demos, which is basic Java code allowing to complete track names and validating routes on the local ski resort, it's basic Java code.

Eclipse LSP client wasn't, I recall, overly impressive

While the goal is not to make it impressive, your feedback about what can be missing in LSP4E is welcome on LSP4E issues channels. Note that LSP is unavoidable, and LSP4E is the only Eclipse client that is likely to ever exist, so don't expect much alternative ;)

I support the idea that the BND Language Server should try to remain independent from JDT or any other Language Server and should try to work standalone.

@maho7791
Copy link
Contributor

If we get some active interest & commitments to work on this I suggest we move this work to a branch & a PR?

Branch would be great.

@maho7791
Copy link
Contributor

maho7791 commented Oct 25, 2023

@mickaelistria Thank you for the snippets and the hints!
Btw: I get a 404 wenn I look at your Github repo link. Is that repo private?

@gg-dim
Copy link

gg-dim commented Oct 25, 2023

@mickaelistria Thank you for the snippets and the hints! Btw: I get a 404 wenn I look at your Github repo link. Is that repo private?

The correct URL is https://github.com/mickaelistria/eclipse-languageserver-demo/tree/master/Le%20LanguageServer%20de%20Chamrousse

@laeubi
Copy link
Contributor Author

laeubi commented Oct 26, 2023

Just looking for createServerLauncher on GitHub should give some example. I used to show https://github.com/mickaelistria/eclipse-languageserver-demo/blob/master/Le LanguageServer de Chamrousse/ in demos, which is basic Java code allowing to complete track names and validating routes on the local ski resort, it's basic Java code.

Thats looking very interesting, I think it would be great to link such "starter" projects at https://github.com/eclipse-lsp4j/lsp4j/blob/main/documentation/README.md#implement-your-language-server (maybe also the one from @pkriens and other implementations)

@laeubi
Copy link
Contributor Author

laeubi commented Oct 26, 2023

I now created:

to just have some branch for experimenting / pushing code and sharing current state ... the server part hopefully will then approach in bndlib some times soon so PDE only will consume that later on.

@pkriens
Copy link
Member

pkriens commented Oct 30, 2023

I am unclear on this now? Are we going to make an LS in bnd or will it happen elsewhere? If it is going to happen elsewhere, please close this issue. If it is going to happen here, I think we should create a branch and maybe project?

@laeubi
Copy link
Contributor Author

laeubi commented Oct 30, 2023

I am unclear on this now? Are we going to make an LS in bnd or will it happen elsewhere? If it is going to happen elsewhere, please close this issue. If it is going to happen here, I think we should create a branch and maybe project?

This all depends abit on the people working on it, I think it would make much sense if it would be part of "bndlib" somehow so it can evolve with changes there and then can be consumed by an artifact (lsp4j based).

The client-side might be part of "bndtools" then for eclipse side, not sure if anyone has experience regarding vscode and/or intellij and if it makes sense to provide client here as well.

@pkriens
Copy link
Member

pkriens commented Oct 31, 2023

More direct, what is the plan?

Should we create a branch on this repository so people can collaborate? Who would be seriously interested to work on this? I do not want this issue to linger for months and then moved to abeyance by the stale bot.

@maho7791
Copy link
Contributor

maho7791 commented Nov 1, 2023

More direct, what is the plan?

Should we create a branch on this repository so people can collaborate? Who would be seriously interested to work on this? I do not want this issue to linger for months and then moved to abeyance by the stale bot.

We are really interested doing some work. So I think a seperate branch would be fine for us.

@pkriens
Copy link
Member

pkriens commented Nov 1, 2023

Created a new branch feature/lsp

Issues can now be discussed in #5861. If needed I can enable projects if we get many people to collaborate?

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

No branches or pull requests

5 participants