This repository is archived and will not be developed any further. If you like the non-lsp-renaming technique using regex behind this plugin, feel free to fork this plugin.
Otherwise, I can recommend using the nvim-jdtls plugin. Though this still does not seem to properly work with the willRename event, you can move the class using the appropriate code action provided by the plugin when hovering over a class name.
This mainly is the reason why I will stop developing this plugin. Because there already is a (better) solution.
If your interested into using the java snippets-part of this plugin, please look here.
A neovim plugin to move and rename java files.
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.
- ripgrep
- nvim-tree.lua (currently the only supported file editor, other may come later if requested)
- LuaSnip (recommended for some java snippets)
- nvim-jdtls (recommended)
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.
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.
- Linux
- MacOS
The plugin can be easily installed using dusing different Plugin Managers.
Lazy
-- other lazy stuff
{
'simaxme/java.nvim'
}
-- other lazy stuffYou will also need to setup the plugin (see 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/"
}
}Due to the owner of the nvim-java also naming his package java there may be compatibility issues. If you are using this package, it is recommended to use the alias simaxme-java:
require("simaxme-java").setup()- 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,interfaceorenumin an empty java file to automatically create a package and class/enum/interface declaration in the file. - autorun snippets for class creation
- javadoc snippets
- type
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 🙃.
