Javacomplete2 to jc.nvim
With the advent of LSP, it’s time to finish the development of my plugin for working with Java in Vim. Goodbye vim-javacomplete2, it was fun to be with you.
But, since I wanted to save my workflow when working with Java applications, I decided to transfer the functionality from vim-jc2 to the new jc.nvim plugin.
And so, meet jc.nvim – neovim plugin for working with Java, with LSP support.
Old functionality
It is clear that the main task of the plugin is the autocompleting of the code when writing it. Now this function works even better, since the Eclipse server operates under the hood. jc.nvim takes care of starting the server with the desired parameters.
To preserve the muscle memory of my fingers, I transfered some functionality from the old plugin. Such as:
- key bindings;
- generation of class elements in the style of the old version, with the choice of fields;
- interface for generating new classes.
Additional functionality
Automatic installation of external utilities
When activating, the plugin will check the presence of the necessary and optional utilities for Java development. First of all, an attempt will be made to install a JDT.LS server using nvim-lsp-Innstaller. Then, if necessary, java-debug will be installed in JDT.LS to debug applications. Also, if necessary, the jol
utility will be downloaded and collected to analyze objects.
Debugging with VIMSPector
The plugin allows you to use VimSpector to debug the applications. There are several commands for that:
JCdebugAttach
– starting debugging by supplying the port to connect to the application;;JCdebugLaunch
– launching the application in debugging mode and connecting to it;JCdebugWithConfig
– the use of pre-installed VimSpector settings.
Refactoring
With the help of nvim-jtdls
, extracts of methods and variables are implemented. There are commands to use these methods:
JCrefactorExtractVar
– default mappings:<leader>jre
;JCrefactorExtractMethod
– default mappings:<leader>jrm
.
Utilities
JCutilJshell
– launch JSell;JCutilBytecode
– extracting bytecode;JCutilJol
– class analysis using JOL;JCutilUpdateConfig
– updating the project configuration in JDT.LS, useful after changind Maven or Gradle configuration.
Usage
For a quick start, the next configuration is sufficient:
call plug#begin('~/.vim/plugged')
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'williamboman/nvim-lsp-installer'
Plug 'puremourning/vimspector'
Plug 'mfussenegger/nvim-jdtls'
Plug 'artur-shaik/jc.nvim'
call plug#end()
lua require('jc').setup{}
After installing all plugins and rebooting vim, when the Java file is opened jc.nvim will check the presence of all the necessary utilities and, if necessary, install the missing ones.