Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add "Eclipse JDT Language Server" as the default lsp server for Java #2510

Closed
JThompson-VI opened this issue May 19, 2022 · 9 comments · Fixed by #2511
Closed

Add "Eclipse JDT Language Server" as the default lsp server for Java #2510

JThompson-VI opened this issue May 19, 2022 · 9 comments · Fixed by #2511
Labels
A-language-server Area: Language server client C-enhancement Category: Improvements E-good-first-issue Call for participation: Issues suitable for new contributors

Comments

@JThompson-VI
Copy link
Contributor

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`
@JThompson-VI JThompson-VI added the C-enhancement Category: Improvements label May 19, 2022
@the-mikedavis the-mikedavis added A-language-server Area: Language server client E-good-first-issue Call for participation: Issues suitable for new contributors labels May 19, 2022
@the-mikedavis
Copy link
Member

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?

@KingTheGuy
Copy link

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?

@JThompson-VI
Copy link
Contributor Author

JThompson-VI commented Oct 11, 2022 via email

@s1ck
Copy link
Contributor

s1ck commented Nov 27, 2022

@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?

@Damjan94
Copy link

Damjan94 commented Dec 9, 2022

I am having the same problem. They have an open issue about it, and it looks like most editors adapt to them...

@Ordoviz
Copy link
Contributor

Ordoviz commented Dec 19, 2022

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/.

@KingTheGuy
Copy link

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 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.

@YoungHaKim7
Copy link

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 path

end

@allaboutevemirolive
Copy link

allaboutevemirolive commented Feb 24, 2024

In my case,

  1. I installed jdtls with @YoungHaKim7 's suggestion
  2. Locate jdtls in this path:
/home/username/.local/bin/jdtls
  1. Add jdtls to my PATH in ~/.bashrc
export PATH="$PATH:/home/username/.local/bin"
  1. NO NEED to modify ~/.config/helix/languages.toml
  2. 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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-language-server Area: Language server client C-enhancement Category: Improvements E-good-first-issue Call for participation: Issues suitable for new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants