Add "Eclipse JDT Language Server" as the default lsp server for Java
JThompson-VI opened this issue ยท 9 comments
Change languages.toml to include the Eclipse JDT Language Server as the default server.
[[language]]
name = "java"
scope = "source.java"
injection-regex = "java"
file-types = ["java"]
roots = ["pom.xml"]
+ language-server = { command = "jdtls" }
indent = { tab-width = 4, unit = " " }Change the wiki to direct users to installation instructions for Eclipse JDT Language Server
## Eclipse JDT Language Server
https://github.com/eclipse/eclipse.jdt.ls
Installation instructions can be found on the [projects README](https://github.com/eclipse/eclipse.jdt.ls)
On MacOS installation can also be done via `brew install jdtls`These changes look good - would you like to submit a PR for the languages.toml change and then update the wiki when that's merged?
i keep getting this lsp error at the start of java files.
"App.java is a non-project file, only syntax errors are reported"
in the same project i tried using vscode and neovim with "jdtls" but those seem to be working fine with no errors.
thoughts?
@Thomas-Jack
I'm using helix mainly for writing Rust but I was playing a little with helix and Java using jdtls since I want to get away from full-blown IDEs. While I see that the LSP is working and giving hints, the code actions don't really work for me. For example, if I implement an interface, it correctly suggests implementing the missing methods, but nothing happens when I select the code action. Is there maybe additional configuration necessary?
I am having the same problem. They have an open issue about it, and it looks like most editors adapt to them...
i keep getting this lsp error at the start of java files. "App.java is a non-project file, only syntax errors are reported"
@KingTheGuy I had the same error and fixed it by adding following minimal pom.xml file to the project root:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
</build>
</project>Also make sure you don't have any .git folders in src/.
i keep getting this lsp error at the start of java files. "App.java is a non-project file, only syntax errors are reported"
@KingTheGuy I had the same error and fixed it by adding following minimal
pom.xmlfile to the project root:<project> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>1</version> <build> <sourceDirectory>${project.basedir}/src</sourceDirectory> </build> </project>Also make sure you don't have any
.gitfolders insrc/.
i actaully ended "fixing" my issues.
[[language]]
name = "java"
scope = "source.java"
injection-regex = "java"
file-types = ["java"]
roots = ["build.xml", "pom.xml", "settings.gradle", "settings.gradle.kts"]
indent = { tab-width = 2, unit = " " }
# jdtl is a python script provided by JDTLS, and must be on $PATH
language-server = { command = "jdtls", args = [
"-configuration", "/home/boots/.cache/jdtls/config",
"-data", "/home/boots/.cache/jdtls/workspace",
]}
the "-configuration" "-data" are the key parts here. someone in helix's matrix chat helped me with it. what they did was basically copy the config that nvim-lspconfig has, those key parts that i mentioned.
https://github.com/eruizc-dev/jdtls-launcher
git clone https://github.com/eruizc-dev/jdtls-launcher.git
Cloning into 'jdtls-launcher'...
remote: Enumerating objects: 241, done.
remote: Counting objects: 100% (85/85), done.
remote: Compressing objects: 100% (52/52), done.
remote: Total 241 (delta 43), reused 50 (delta 28), pack-reused 156
Receiving objects: 100% (241/241), 48.74 KiB | 9.75 MiB/s, done.
Resolving deltas: 100% (125/125), done.
$ cd jdtls-launcher
$ ls
CONTRIBUTING.md install.sh jdtls-launcher.sh LICENSE README.md
$ ./install.sh
INFO: Downloading JDTLS-LAUNCHER
-#O=# # #
INFO: Extracting JDTLS-LAUNCHER
INFO: Creating symlink at /home/gy/.local/bin/jdtls
Installing jdtls...
jdt-language-server-1.28.0-202309221544 is going to be installed
########################################################################################################################### 100.0%########################################################################################################################### 100.0%
Installing lombok...
########################################################################################################################### 100.0%
Lombok installation succesfull
JDTLS installation succesfull
INFO: Installation successful
INFO: Ensure /home/gy/.local/bin is in pathend
In my case,
- I installed
jdtlswith @YoungHaKim7 's suggestion - Locate
jdtlsin this path:
/home/username/.local/bin/jdtls
- Add
jdtlsto myPATHin~/.bashrc
export PATH="$PATH:/home/username/.local/bin"
- NO NEED to modify
~/.config/helix/languages.toml - Check
jdtls's version on the terminal:
$ jdtls --version
jdtls-launcher v1.2.0
equinox-launcher 1.6.700.v20231214-2017
jdtls-core 1.34.0.202402221644
lombok custom
java 21.0.2 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 21.0.2+13-LTS-58)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.2+13-LTS-58, mixed mode, sharing)
P/S: I'm sure there is a more clean way to do this without forking jdtls-launcher.