Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork77
nvim-java/nvim-java
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Just install and start writingpublic static void main(String[] args).
Warning
You cannot usenvim-java alongsidenvim-jdtls. So removenvim-jdtls before installing this
Demo.mp4
- ✅ Spring Boot Tools
- ✅ Diagnostics & Auto Completion
- ✅ Automatic Debug Configuration
- ✅ Organize Imports & Code Formatting
- ✅ Running Tests
- ✅ Run & Debug Profiles
- ✅Code Actions
- Everything necessary will be installed automatically
- Usesnvim-lspconfig to setup
jdtls - Realtime server settings updates is possible usingneoconf
- Auto loads necessary
jdtlsplugins- Supported plugins are,
spring-boot-toolslombokjava-testjava-debug-adapter
- Supported plugins are,
🔸details
Following are forks of original repositories pre-configured for java. If youdon't know how to get started, use one of the following to get started.You can click onn commits ahead of link to see the changes made on top of the original project
- Install the plugin
Usinglazy.nvim
return {'nvim-java/nvim-java'}
- Setup nvim-java before
lspconfig
require('java').setup()
- Setup jdtls like you would usually do
require('lspconfig').jdtls.setup({})
Yep! That's all :)
🔸details
JavaBuildBuildWorkspace- Runs a full workspace buildJavaBuildCleanWorkspace- Clear the workspace cache(for now you have to close and reopen to restart the language server afterthe deletion)
JavaRunnerRunMain- Runs the application or selected main class (if thereare multiple main classes)
:JavaRunnerRunMain:JavaRunnerRunMain<arguments><to><pass>
JavaRunnerStopMain- Stops the running applicationJavaRunnerToggleLogs- Toggle between show & hide runner log window
JavaDapConfig- DAP is autoconfigured on start up, but in case you want toforce configure it again, you can use this API
JavaTestRunCurrentClass- Run the test class in the active bufferJavaTestDebugCurrentClass- Debug the test class in the active bufferJavaTestRunCurrentMethod- Run the test method on the cursorJavaTestDebugCurrentMethod- Debug the test method on the cursorJavaTestViewLastReport- Open the last test report in a popup window
JavaProfile- Opens the profiles UI
JavaRefactorExtractVariable- Create a variable from value at cursor/selectionJavaRefactorExtractVariableAllOccurrence- Create a variable for alloccurrences from value at cursor/selectionJavaRefactorExtractConstant- Create a constant from the value at cursor/selectionJavaRefactorExtractMethod- Create a method from the value at cursor/selectionJavaRefactorExtractField- Create a field from the value at cursor/selection
JavaSettingsChangeRuntime- Change the JDK version to another
🔸details
build.build_workspace- Runs a full workspace build
require('java').build.build_workspace()
build.clean_workspace- Clear the workspace cache(for now you have to close and reopen to restart the language server afterthe deletion)
require('java').build.clean_workspace()
built_in.run_app- Runs the application or selected main class (if thereare multiple main classes)
require('java').runner.built_in.run_app({})require('java').runner.built_in.run_app({'arguments','to','pass','to','main'})
built_in.stop_app- Stops the running application
require('java').runner.built_in.stop_app()
built_in.toggle_logs- Toggle between show & hide runner log window
require('java').runner.built_in.toggle_logs()
config_dap- DAP is autoconfigured on start up, but in case you want to forceconfigure it again, you can use this API
require('java').dap.config_dap()
run_current_class- Run the test class in the active buffer
require('java').test.run_current_class()
debug_current_class- Debug the test class in the active buffer
require('java').test.debug_current_class()
run_current_method- Run the test method on the cursor
require('java').test.run_current_method()
debug_current_method- Debug the test method on the cursor
require('java').test.debug_current_method()
view_report- Open the last test report in a popup window
require('java').test.view_last_report()
require('java').profile.ui()
extract_variable- Create a variable from value at cursor/selection
require('java').refactor.extract_variable()
extract_variable_all_occurrence- Create a variable for all occurrences fromvalue at cursor/selection
require('java').refactor.extract_variable_all_occurrence()
extract_constant- Create a constant from the value at cursor/selection
require('java').refactor.extract_constant()
extract_method- Create method from the value at cursor/selection
require('java').refactor.extract_method()
extract_field- Create a field from the value at cursor/selection
require('java').refactor.extract_field()
change_runtime- Change the JDK version to another
require('java').settings.change_runtime()
🔸details
Neoconf can be used to manage LSPsetting including jdtls. Neoconf allows global configuration as well as projectvice configurations. Here is how you can set Jdtls setting onneoconf.json
{"lspconfig": {"jdtls": {"java.configuration.runtimes": [ {"name":"JavaSE-21","path":"/opt/jdk-21","default":true } ] } }}Pass the settings to Jdtls setup.
require('lspconfig').jdtls.setup({settings= {java= {configuration= {runtimes= { {name="JavaSE-21",path="/opt/jdk-21",default=true, } } } } }})
🔸details
For most users changing the default configuration is not necessary. But if youwant, following options are available
{-- list of file that exists in root of the projectroot_markers= {'settings.gradle','settings.gradle.kts','pom.xml','build.gradle','mvnw','gradlew','build.gradle','build.gradle.kts','.git', },-- load java test pluginsjava_test= {enable=true, },-- load java debugger pluginsjava_debug_adapter= {enable=true, },spring_boot_tools= {enable=true, },jdk= {-- install jdk using mason.nvimauto_install=true, },notifications= {-- enable 'Configuring DAP' & 'DAP configured' messages on start updap=true, },-- We do multiple verifications to make sure things are in place to run this-- pluginverification= {-- nvim-java checks for the order of execution of following-- * require('java').setup()-- * require('lspconfig').jdtls.setup()-- IF they are not executed in the correct order, you will see a error-- notification.-- Set following to false to disable the notification if you know what you-- are doinginvalid_order=true,-- nvim-java checks if the require('java').setup() is called multiple-- times.-- IF there are multiple setup calls are executed, an error will be shown-- Set following property value to false to disable the notification if-- you know what you are doingduplicate_setup_calls=true,-- nvim-java checks if nvim-java/mason-registry is added correctly to-- mason.nvim plugin.-- IF it's not registered correctly, an error will be thrown and nvim-java-- will stop setupinvalid_mason_registry=true, },}🔸details
Following is the high level idea. Jdtls is the language server nvim-javacommunicates with. However, we don't have all the features we need just inJdtls. So, we are loading java-test & java-debug-adapter extensions when welaunch Jdtls. Once the language server is started, we communicate with thelanguage server to do stuff.
For instance, to run the current test,
- Request Jdtls for test classes
- Request Jdtls for class paths, module paths, java executable
- Request Jdtls to start a debug session and send the port of the session back
- Prepare TCP connections to listen to the test results
- Start nvim-dap and let user interactions to be handled by nvim-dap
- Parse the test results as they come in
- Once the execution is done, open a window show the test results
┌────────────┐ ┌────────────┐ │ │ │ │ │ Neovim │ │ VSCode │ │ │ │ │ └─────▲──────┘ └──────▲─────┘ │ │ │ │ │ │ │ │┌───────▼───────┐ ┌──────────────▼──────────────┐│ │ │ ││ nvim-java │ │ Extension Pack for Java ││ │ │ │└───────▲───────┘ └──────────────▲──────────────┘ │ │ │ │ │ │ │ │ │ │ │ ┌───────────┐ │ │ │ │ │ └──────────────► JDTLS ◄────────────┘ │ │ └───▲───▲───┘ │ │ │ │ │ │ │ │ │ │ ┌───────────────┐ │ │ ┌────────────────────────┐ │ │ │ │ │ │ │ java-test ◄────────┘ └─────────► java-debug-adapter │ │ │ │ │ └───────────────┘ └────────────────────────┘spring-boot.nvim is the onethat starts sts4 & do other necessary
jdtlssts4sync command registrationinnvim-java.nvim-jdtls is a plugin that follows"Keep it simple, stupid!" approach. If you love customizing things by yourself,then give nvim-jdtls a try.
Warning
You cannot usenvim-java alongsidenvim-jdtls. So removenvim-jdtlsbefore installing this
About
Painless Java in Neovim
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.