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

Include LSP Support #68

Open
Sironheart opened this issue Sep 4, 2023 · 18 comments
Open

Include LSP Support #68

Sironheart opened this issue Sep 4, 2023 · 18 comments

Comments

@Sironheart
Copy link

There are a few language servers out there for nix. It would be great if you could use those from within JetBrains Products. An example library to do this 'quick' and 'dirty' would be https://github.com/ballerina-platform/lsp4intellij. Other than that, JetBrains Products started allowing plugin developers to communicate with LSPs from the Plugin, starting from 2023.2 (see: Language Server Protocol for Plugin Developers)
Would love to be able to use LSPs in combination with IntelliJ, and thank you in advance for your time :)

@JojOatXGME
Copy link
Contributor

Hi, do you have some specific LSPs in mind?

I was not aware of this new functionality in IDEA. Looks like it just got introduced by 2023.2, which means it might be a bit tricky to implement without loosing support for older versions of the IDE. (Usually, I would drop support for older versions in about one year.) I am also a bit confused that the Community Edition of IntelliJ is not listed in the blog post. Anyway, if there is a good LSP, it might be an interesting option.

@Sironheart
Copy link
Author

There are two LSPs I know of that are somewhat Feature complete. Nil (https://github.com/oxalica/nil) and Nixd (https://github.com/nix-community/nixd).

I hoped that there could be some "easy" option to make this backwards compatible, like checking if something is available in the classpath. Also I hoped that there would be some easy way to add ultimate features if there it is the IDE. Maybe I'm just plain wrong with my assumptions :) Would love to see this feature and the future :)
If I can help you in any way just say so :)

@JojOatXGME
Copy link
Contributor

JojOatXGME commented Sep 10, 2023

FYI, I tried out the LSP integration of IntelliJ on the lsp branch (build). I did not invest much time into that, but it did seem to work with nil. I also tried nixd, but the LSP implementation of IntelliJ throw an exception due to an unexpected token whenever nixd was not able to resolve a reference. Looks like either nixd or IntelliJ has a bug in the protocol implementation.

Anyway, it would be more effort to integrate this without removing support for the previous versions of IntelliJ. It is also a bummer that this feature only works with paid versions of IDEA. Maybe I try out lsp4intellij later, but I fear I will not have time for that in the next few weeks.

@JojOatXGME
Copy link
Contributor

JojOatXGME commented Sep 24, 2023

I tried out lsp4intellij with nil, but it didn't feel very stable on a first glance. I run into two different NullPointerException and one IllegalArgumentException from within the library within a few minutes of testing.

  • Clicking on the status icon before you have opend any Nix file.
  • Clicking on an identifier, for which the Language Server cannot resolve the definition.
  • Clicking on a variable in a let expression.

I may look a bit closer, but I am currently a bit sceptical.

EDIT: FIY, I also pushed the code to the lsp branch again. See commit ac74690.

@cottand
Copy link
Contributor

cottand commented Jan 16, 2024

hey @JojOatXGME I think providing LSP support for nix-idea would be huge - the current lack of nixd is the only reason I use VSCode instead of intelliJ for Nix (try it yourself to see the difference!). In every other aspect IntelliJ is better.

I know nothing about LSPs but I have developed an IDEA plugin before and I am happy to help.

  • For nixd: would it be possible to narrow down what part of the LSP protocol nixd is non-compliant with? Ideally we could get them to fix it or we could just submit a fix with them ourselves
  • For your backwards compatibility concerns - they are totally fair. I suggest maintaining the 'ahead' version of this plugin (with minimum compatible being 2023.2) and we can package it via Nix to make it very easy for other people to install it manually in IDEA, without having to go through the official marketplace. Potentially we could even provide a patched IDEA (from nixpkgs) that comes with nix-idea installed to make this extra easy - but that's a long shot

What do you think?

@JojOatXGME
Copy link
Contributor

@cottand The main reason why I haven't spent more time on implementing LSP-support using the LSP integration is that it would only work in paid versions of IDEA. I only have the community editions, so I wouldn't be able to use it. I fear JetBrains might be reluctant to put this feature into the community editions, as it would make the premium features less worthwhile.

If you would like to spend time on this, I would be open to merge the pull request.

BTW, After my disappointing experiment with lsp4intellij, I also thought about implementing my own LSP integration for a short moment, but then I realized that I don't have time for such a project. 😄

For nixd: would it be possible to narrow down what part of the LSP protocol nixd is non-compliant with?

Not sure, I haven't spent much time on debugging the issue.

For your backwards compatibility concerns

I am not sure if this would still be a problem as IntelliJ 2024.1 might be released in a few months. Anyway, I don't think that this should block us. We could probably drop support for 2023.1 earlier than usual. (The old version of the plugin would still work for previous versions of IDEA.)

we can package it via Nix

Packaging the plugin via Nix is something I would also like to see. However, I think this would be another independent topic. I only spend a limited time thinking about this topic so far. I imagine it might be tricky. Note that the plugin currently uses the official Gradle plugin from JetBrains. This plugin downloads all the dependencies on demand. I am not sure how easy it is to make all of that work in an offline build environment as used by Nix. There are probably some dependencies currently still missing in nixpkgs.

@cottand
Copy link
Contributor

cottand commented Jan 19, 2024

BTW, After my disappointing experiment with lsp4intellij, I also thought about implementing my own LSP integration for a short moment, but then I realized that I don't have time for such a project. 😄

Also completely fair :D

If you would like to spend time on this, I would be open to merge the pull request.

Thanks, I will think about it. I had not realised that the community edition does not support LSPs (yet?). FYI as an open source contributor you could request an Ultimate licence.

We could probably drop support for 2023.1 earlier than usual. (The old version of the plugin would still work for previous versions of IDEA.)

👍 makes sense

As for packaging via Nix, I can make a PR if it is something you want and there are benefits for. I think I can manage Gradle if the dependencies are locked, which is usually the case for JARs.

@JojOatXGME
Copy link
Contributor

JojOatXGME commented Jan 20, 2024

I had not realised that the community edition does not support LSPs (yet?).

I hope it is yet. However, I can imagine that they fear that it would diminish the value proposition of the ultimate edition. People could easily start using an LSP for JavaScript and other languages, for which you have to pay right now. I haven't found any specific information about that when I looked into it.

As for packaging via Nix, I can make a PR if it is something you want and there are benefits for. I think I can manage Gradle if the dependencies are locked, which is usually the case for JARs.

I personally don't need it right now. So I wouldn't prioritize it that high as long as nobody complains. It just seems strange that this project kind of ignores the packaging process of Nix. Also note that the Gradle plugin org.jetbrains.intellij may download resources directly, bypassing the repository management of Gradle. I think I have seen it in the past. (You can still do it, of course, if you like.)

@cottand
Copy link
Contributor

cottand commented Jan 21, 2024

I personally don't need it right now. So I wouldn't prioritize it that high as long as nobody complains.

done :)

sounds good, I will consider spending time on this, and we can revisit if JetBrains makes lsp available for the community edition

@abovestratosphere
Copy link

hey, i think even releasing a basic version like the one you linked above would be a huge boon (built it myself to try out, and the basic functionality it offers is already satisfactory for most of my needs). I really don't wanna have to switch to vscode just for nix files...

@JojOatXGME
Copy link
Contributor

@abovestratosphere Do you know if you have tried the version with lsp4intellij, or the version using the LSP integration of IDEA? I was not convinced by lsp4intellij as it did throw a lot of exception during my tests. I am probably not able to fix them. However, if you think it is still valuable, I guess I could think about integrating it behind some feature flag.

Regarding the solution using JetBrains LSP integration (paid versions only): I have recently seen some analytics from JetBrains, and was surprised how many users of the plugin seem to use IntelliJ Ultimate. So, maybe integrating this solution makes more sense as I though initially. I am still only using the community edition, through. 🤷‍♂️ (Do you have a paid version of IDEA?)

@abovestratosphere
Copy link

abovestratosphere commented Apr 10, 2024

looks like the version i built was e815bfe, all I did was bump the supported IDE version on that commit so it could work for me, so not the lsp4intellij commit. I'm honestly not clear on the difference between using lsp4intellij vs whatever you did in the first commit (not familiar with jetbrains plugin ecosystem at all).
That being said, your first prototype commit is honestly already a huuuuge improvement (being able to just navigate to a nix file by using the "go to source" hotkey on a file path is already a game changer). The only issue is, without it being officially released, I have to constantly bump the version on it and rebuild, like recently everything got updated to 2024.1 so it broke again, which is a hassle.

I personally don't use intellij since I dont work in java but my company sponsors all jetbrains licenses, so yes I have all paid jetbrains IDEs.

FWIW, most folks I know use vscode or neovim for nix (because of lsp support), but I definitely know other diehard jetbrains users who are dying for nix lsp support in this plugin, there's dozens of us :)

@hab25
Copy link

hab25 commented Apr 17, 2024

@abovestratosphere did you use nixd or nil? If nixd, did you run into the issues described by @JojOatXGME, which are seemingly protocol-related?

@abovestratosphere
Copy link

I used whatever that commit e815bfe used, which is nil

@amacfie
Copy link

amacfie commented Apr 24, 2024

I haven't tried it but there's https://github.com/redhat-developer/lsp4ij

@JojOatXGME
Copy link
Contributor

I just implemented and released some experimental solution using JetBrains' LSP API. See version 0.4.0.13 and commit cfe2ef1. There are currently no automatic tests, and I only tested the basics manually. I hope everything works.

Settings page for enabling and configuring the language server

As it is using JetBrains' API, it only works for paid versions of IDEA. If someone wants to try out https://github.com/redhat-developer/lsp4ij (thanks @amacfie) to make it available for free, I am happy to help. I may also take a look at it at some point, but probably not in the near future.

PS: During my short tests, I no-longer noticed the exception I have observed with nixd in the past. However, nil still provided a better experience during my tests, as it was more responsive. In contrast to nil, nixd also wasn't able to resolve the paths in the files I used.

@abovestratosphere
Copy link

@JojOatXGME thanks a lot. just tested, it works great for me.

@angelozerr
Copy link

I haven't tried it but there's https://github.com/redhat-developer/lsp4ij

LSP4IJ has been released.

If you want to try to integrate your language server without developping an IJ plugin please read https://github.com/redhat-developer/lsp4ij/blob/main/docs%2FUserDefinedLanguageServer.md

If you want to try to integrate your language server by developping an IJ plugin please read https://github.com/redhat-developer/lsp4ij/blob/main/docs%2FDeveloperGuide.md

If you want to know the LSP support please read https://github.com/redhat-developer/lsp4ij/blob/main/docs%2FLSPSupport.md

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

7 participants