neoclide / coc-java

Java extension for coc.nvim
Eclipse Public License 1.0
452 stars 39 forks source link
java neovim vim vscode

coc-java

License

Fork of vscode-java to works with coc.nvim.

Provides Java ™ language support via Eclipse ™ JDT Language Server, which utilizes Eclipse ™ JDT, M2Eclipse and Buildship.

Quick Start

  1. Install this extension by run command:
:CocInstall coc-java
  1. On the following platforms, the extension should activate without any setup : win32-x64, darwin-x64, darwin-arm64, linux-x64, linux-arm64.\ If on another platform, or using the "universal" version, you can set a Java Development Kit. It must be Java 17 or above.

  2. Optionally, download and install a Java Development Kit for your project (Java 1.5 or above is supported). See Project JDKs for more details

  3. Extension is activated when you first access a Java file

    • Recognizes projects with Maven or Gradle build files in the directory hierarchy.

Note: this extension comes with bunlded jdt.ls from 1.14.0, the same as vscode-java.

Setting the JDK

Now that Java extension will publish platform specific versions, it will embed a JRE for supported platforms such as win32-x64, linux-x64, linux-arm64, darwin-x64, darwin-arm64. The embedded JRE is used to launch the Language Server for Java. Users are only responsible for configuring Project JDKs to compile your Java projects.

The following part is only kept for the universal version without embedded JRE.

The tooling JDK will be used to launch the Language Server for Java. And by default, will also be used to compile your projects. Java 17 is the minimum required version.\

The path to the Java Development Kit is searched in the following order:

The tooling JDK will be used to launch the Language Server for Java. And by default, will also be used to compile your projects. Java 17 is the minimum required version.

Project JDKs

If you need to compile your projects against a different JDK version, it's recommended you configure the java.configuration.runtimes property in your user settings, eg:

"java.configuration.runtimes": [
  {
    "name": "JavaSE-1.8",
    "path": "/path/to/jdk-8",
  },
  {
    "name": "JavaSE-11",
    "path": "/path/to/jdk-11",
  },
  {
    "name": "JavaSE-21",
    "path": "/path/to/jdk-21",
    "default": true
  },
]

The default runtime will be used when you open standalone Java files.

Features

See the changelog for the latest release.

Available commands

The following commands are available:

Name Command Description
Reload Projects java.projectConfiguration.update It forces project configuration / classpath updates (eg. dependency changes or Java compilation level), according to the project build descriptor.
Import Java Projects into Workspace java.project.import.command detects and imports all the Java projects into the Java Language Server workspace.
Open Java Language Server Log File java.open.serverLog opens the Java Language Server log file, useful for troubleshooting problems.
Open Java Extension Log File java.open.clientLog opens the Java extension log file, useful for troubleshooting problems.
Open All Log Files java.open.logs opens both the Java Language Server log file and the Java extension log file.
Force Java Compilation java.workspace.compile manually triggers compilation of the workspace.
Rebuild Projects java.project.build manually triggers a full build of the selected projects.
Open Java Formatter Settings java.open.formatter.settings opens the Eclipse formatter settings. Creates a new settings file if none exists.
Clean Java Language Server Workspace java.clean.workspace cleans the Java language server workspace.
Attach Source java.project.updateSourceAttachment.command attaches a jar/zip source to the currently opened binary class file.
Add Folder to Java Source Path java.project.addToSourcePath.command adds the selected folder to its project source path.
Remove Folder from Java Source Path java.project.removeFromSourcePath.command removes the selected folder from its project source path.
List All Java Source Paths java.project.listSourcePaths.command lists all the Java source paths recognized by the Java Language Server workspace.
Show Build Job Status java.show.server.task.status shows the Java Language Server job status in Visual Studio Code terminal.
Go to Super Implementation java.action.navigateToSuperImplementation goes to the super implementation for the current selected symbol in editor.

Supported settings

The following coc.nvim settings are supported (checkout :h coc-configuration for how to use them):

Settings added by coc-java:

New in 1.15.0

Semantic Highlighting

To enable semantic highlighting support, use configuration:

"semanticTokens.enable": true,

For java filetype only, use:

"[java]": {
  "semanticTokens.enable": true,
}

Checkout :h coc-configuration-scope.

Buffer not work

The jdt.ls requires buffer saved to disk to work, save the buffer by :w command and reload it by :e command in your vim. Or create the file on disk before buffer create.

Compiler warnings

To customize compiler warnings, create the file root_project/.settings/org.eclipse.jdt.core.prefs with values presented at https://help.eclipse.org/neon/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/JavaCore.html

"Classpath is incomplete" warning

See https://github.com/redhat-developer/vscode-java/wiki/%22Classpath-is-incomplete%22-warning

Troubleshooting

Feedback

License

EPL 1.0, See LICENSE for more information.