simaxme/java.nvim

github github
programming-languages-support
stars 17
issues 0
subscribers 1
forks 2
CREATED

2023-11-07

UPDATED

4 months ago


java.nvim

A neovim plugin to move and rename java files.

Introduction

I am a Java developer and am loving to use neovim. Nevertheless, refactoring was the thing that always brought me back to JetBrains IDEs. Although nvim-jdtls is existing, which is able to simply rename symbols, file renames were never possible with it. For instance, tsserver-LSP has this feature. Because I really wanted to use neovim as my dailydriver and file-renames are essential, I have written this plugin.

Dependencies

Function of this plugin

In current state, this plugin is a addition to nvim-jdtls. It allows you to rename .java files and looks for any reference to the name and updates the import statements and symbol usages automaticaly. This does only work due to the use of lua-patterns and regex. I hope this plugin wil help someone with this basic feature of file refactoring.

Why have I named it java.nvim?

This can be simply answered: I want to add some features besides the refactoring of files that are helping in everyday Java use. For instance, I will try to add the ability for simple LuaSnip snippets that allow you to create a default class/interface/enum by using a simple snippet without needing to write all the same stuff again and again.

Supported platforms

  • Linux
  • MacOS

Installing the plugin

The plugin can be easily installed using dusing different Plugin Managers.

Lazy

-- other lazy stuff
{
    'simaxme/java.nvim'
}
-- other lazy stuff

You will also need to setup the plugin (see Configuring the plugin)

Configuring the plugin

You can setup java.nvim with the following line:

require("java").setup()

However, there are some tweaks you can make (default configuration):

require("java").setup {
    rename = {
        enable = true, -- enable the functionality for renaming java files
        nvimtree = true, -- enable nvimtree integration
        write_and_close = false -- automatically write and close modified (previously unopened) files after refactoring a java file
    },
    snippets = {
        enable = true -- enable the functionality for java snippets
    },
    root_markers = { -- markers for detecting the package path (the package path should start *after* the marker)
        "main/java/",
        "test/java/"
    }
}

All current functionalities

  • Detect file renames in nvim-tree and automatically update the class name and every associated files with the symbol.
  • Snippet integration with LuaSnip
    • type class, interface or enum in an empty java file to automatically create a package and class/enum/interface declaration in the file.
    • autorun snippets for class creation
    • javadoc snippets

After configuration

Go to your nvim-tree pane and execute a simple r on a java file or a package. Magic will happen and you will not have to do anything 🙃.