A language server is a separate program that understands one language and answers an editor’s questions about it: what can follow this dot, where is this method defined, who calls it. The editor and the server talk through the Language Server Protocol (LSP), so one Java server can serve Neovim, VS Code and others. For Java, that server is jdtls, the Eclipse JDT Language Server, built on the same compiler and project model as the Eclipse IDE.
How LazyVim starts jdtls
Neovim has an LSP client built in, but jdtls needs more than a plain start command. It needs a workspace folder per project, extra JAR “bundles” for debugging and testing, and a few Java-only commands. The nvim-jdtls plugin handles those details.
’s lang.java extra puts the pieces together:
- installs the
jdtlspackage. - nvim-jdtls starts jdtls when the first
.javafile opens, and reuses the same server for every file in that project. - The project root is found by looking upward for markers such as
mvnw,gradleworpom.xml. - Lombok support is switched on: the extra passes the
lombok.jarthat ships inside Mason’s jdtls package as a Java agent.
You don’t need to copy any of this into your configuration. The Java extra page shows the defaults for reference only.
Completion while you type
Open CatalogController.java from module 9 of the companion code. Its one endpoint asks the repository for a page of catalog items:
@GetMapping("/catalog")
PagedModel<CatalogItem> catalog(Pageable pageable) {
return new PagedModel<>(repository.findCatalog(pageable));
}
Delete Catalog(pageable) so the line ends in repository.find, and a completion menu opens. On our test it listed 41 entries, starting with findAll, findCatalog and count: the methods ProductRepository declares plus the ones it inherits from JpaRepository. Press Enter (or Ctrl-y) to accept an entry. LazyVim uses the blink.cmp completion engine, which shows the method’s documentation next to the menu.
Hover and go to definition
Put the cursor on findCatalog and press K. A small window shows the full signature, Page<CatalogItem> ProductRepository.findCatalog(Pageable pageable), and the module it comes from.
Now press gd, for “go to definition”. Neovim jumps to ProductRepository.java, to the line that declares the method:
@Query("select p.name, c.name from Product p join p.category c order by p.id")
Page<CatalogItem> findCatalog(Pageable pageable);
Ctrl-o takes you back to where you were. Two related jumps are worth knowing: gy goes to the definition of a variable’s type, and gI goes to implementations. Try gI on findCatalog: it lands on the same interface line, because no class in the project implements ProductRepository. Spring Data creates that implementation at runtime, so the editor has nothing else to show.
Find every usage
With the cursor on findCatalog, press gr for references. A picker lists three places: the controller line above and two tests in CatalogTest.java. Type to filter, move with the arrow keys, and press Enter to open one. This is the same list IntelliJ IDEA calls “Find Usages”.
Search symbols by name
Sometimes you know a name but not the file. Two pickers search symbols, which are classes, methods and fields:
<leader>sssearches the symbols of the current file.<leader>is the space bar in LazyVim.<leader>sSsearches the whole workspace, including the JDK and your dependencies.
Typing CatalogItem in the workspace search finds the record in info.mnafshin.springuniverse.shop at once. For files rather than symbols, <leader><space> finds files by name and <leader>/ searches their text.
Keep the project model in step
jdtls reads your pom.xml once, when it imports the project. If you add a dependency or change a version, run :JdtUpdateConfig so it reads the build again. If the workspace ever gets confused, for example after you delete your local Maven repository, :JdtWipeDataAndRestart throws away jdtls’s cached workspace (not your code) and imports the project from scratch.
One side effect surprises many people. While importing, jdtls writes Eclipse metadata files, .project, .classpath and a .settings/ folder, into each Maven module. They are harmless, but add them to your .gitignore so they don’t end up in commits.
Recap
- jdtls is the Java language server; nvim-jdtls starts it with the workspace and extras it needs, and LazyVim’s
lang.javaextra wires both up, including Lombok. - Completion opens as you type; accept with Enter or
Ctrl-y. Kshows hover information,gdgoes to the definition,gyto the type,gIto implementations andgrlists references.<leader>ssand<leader>sSsearch symbols in the file or the workspace.- Run
:JdtUpdateConfigafter build changes, and ignore.project,.classpathand.settings/in Git.
Series: Neovim as a Java IDE. Previous: Neovim and LazyVim for Java: installing the editor, a JDK and the starter · Next: Diagnostics and quick fixes for Java in Neovim
Sources
Official documentation and well-known tutorials read while writing this article. The wording here is our own.
- Eclipse JDT Language Server (eclipse.jdt.ls) README
- nvim-jdtls README
- LazyVim: Java extra
- LazyVim: LSP keymaps
- Neovim: LSP documentation
- Language Server Protocol overview
- Lorenzo Bettini: Neovim and Java with LazyVim, part 2: IDE mechanisms
- Lorenzo Bettini: Neovim and Java with LazyVim, part 3: Dependencies and Maven
- Trinity Logic: A Terminal-First Java and Maven Setup — Neovim, jdtls and the Build Loop
Comments