-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathnvim-java.txt
More file actions
527 lines (372 loc) · 16.2 KB
/
nvim-java.txt
File metadata and controls
527 lines (372 loc) · 16.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
*nvim-java.txt* For Neovim >= 0.9.4 Last change: 2024 December 24
==============================================================================
Table of Contents *nvim-java-table-of-contents*
1. nvim-java |nvim-java-nvim-java|
- Demo |nvim-java-demo|
- Features |nvim-java-features|
- Why |nvim-java-why|
- How to Install |nvim-java-how-to-install|
- Commands |nvim-java-commands|
- APIs |nvim-java-apis|
- How to Use JDK X.X Version? |nvim-java-how-to-use-jdk-x.x-version?|
- Configuration |nvim-java-configuration|
- Architecture |nvim-java-architecture|
- Projects Acknowledgement |nvim-java-projects-acknowledgement|
2. Links |nvim-java-links|
==============================================================================
1. nvim-java *nvim-java-nvim-java*
Just install and start writing `public static void main(String[] args)`.
[!CAUTION] You cannot use `nvim-java` alongside `nvim-jdtls`. So remove
`nvim-jdtls` before installing this
[!TIP] You can find cool tips & tricks here
https://github.com/nvim-java/nvim-java/wiki/Tips-&-Tricks
[!NOTE] If you are facing errors while using, please check troubleshoot wiki
https://github.com/nvim-java/nvim-java/wiki/Troubleshooting
DEMO *nvim-java-demo*
<https://github.com/nvim-java/nvim-java/assets/18459807/047c8c46-9a0a-4869-b342-d5c2e15647bc>
FEATURES *nvim-java-features*
- Spring Boot Tools
- Diagnostics & Auto Completion
- Automatic Debug Configuration
- Organize Imports & Code Formatting
- Running Tests
- Run & Debug Profiles
- Code Actions <https://github.com/nvim-java/nvim-java/wiki/Tips-&-Tricks#running-code-actions>
WHY *nvim-java-why*
- Everything necessary will be installed automatically
- Uses nvim-lspconfig <https://github.com/neovim/nvim-lspconfig> to setup `jdtls`
- Realtime server settings updates is possible using neoconf <https://github.com/folke/neoconf.nvim>
- Auto loads necessary `jdtls` plugins
- Supported plugins are,
- `spring-boot-tools`
- `lombok`
- `java-test`
- `java-debug-adapter`
HOW TO INSTALL *nvim-java-how-to-install*
:small_orange_diamond:details ~
STARTER CONFIGS (RECOMMEND FOR NEWBIES) ~
Following are forks of original repositories pre-configured for java. If you
don’t know how to get started, use one of the following to get started. You
can click on **n commits ahead of** link to see the changes made on top of the
original project
- LazyVim <https://github.com/nvim-java/starter-lazyvim>
- Kickstart <https://github.com/nvim-java/starter-kickstart>
- AstroNvim <https://github.com/nvim-java/starter-astronvim>
CUSTOM CONFIGURATION INSTRUCTIONS ~
- Install the plugin
Using lazy.nvim <https://github.com/folke/lazy.nvim>
>lua
return {'nvim-java/nvim-java'}
<
- Setup nvim-java before `lspconfig`
>lua
require('java').setup()
<
- Setup jdtls like you would usually do
>lua
require('lspconfig').jdtls.setup({})
<
Yep! That’s all :)
COMMANDS *nvim-java-commands*
:small_orange_diamond:details ~
BUILD ~
- `JavaBuildBuildWorkspace` - Runs a full workspace build
- `JavaBuildCleanWorkspace` - Clear the workspace cache (for now you have to
close and reopen to restart the language server after the deletion)
RUNNER ~
- `JavaRunnerRunMain` - Runs the application or selected main class (if there
are multiple main classes)
>vim
:JavaRunnerRunMain
:JavaRunnerRunMain <arguments> <to> <pass>
<
- `JavaRunnerStopMain` - Stops the running application
- `JavaRunnerToggleLogs` - Toggle between show & hide runner log window
DAP ~
- `JavaDapConfig` - DAP is autoconfigured on start up, but in case you want to
force configure it again, you can use this API
TEST ~
- `JavaTestRunCurrentClass` - Run the test class in the active buffer
- `JavaTestDebugCurrentClass` - Debug the test class in the active buffer
- `JavaTestRunCurrentMethod` - Run the test method on the cursor
- `JavaTestDebugCurrentMethod` - Debug the test method on the cursor
- `JavaTestViewLastReport` - Open the last test report in a popup window
PROFILES ~
- `JavaProfile` - Opens the profiles UI
REFACTOR ~
- `JavaRefactorExtractVariable` - Create a variable from value at cursor/selection
- `JavaRefactorExtractVariableAllOccurrence` - Create a variable for all
occurrences from value at cursor/selection
- `JavaRefactorExtractConstant` - Create a constant from the value at cursor/selection
- `JavaRefactorExtractMethod` - Create a method from the value at cursor/selection
- `JavaRefactorExtractField` - Create a field from the value at cursor/selection
SETTINGS ~
- `JavaSettingsChangeRuntime` - Change the JDK version to another
APIS *nvim-java-apis*
:small_orange_diamond:details ~
BUILD ~
- `build.build_workspace` - Runs a full workspace build
>lua
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 after
the deletion)
>lua
require('java').build.clean_workspace()
<
RUNNER ~
- `built_in.run_app` - Runs the application or selected main class (if there
are multiple main classes)
>lua
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
>lua
require('java').runner.built_in.stop_app()
<
- `built_in.toggle_logs` - Toggle between show & hide runner log window
>lua
require('java').runner.built_in.toggle_logs()
<
DAP ~
- `config_dap` - DAP is autoconfigured on start up, but in case you want to force
configure it again, you can use this API
>lua
require('java').dap.config_dap()
<
TEST ~
- `run_current_class` - Run the test class in the active buffer
>lua
require('java').test.run_current_class()
<
- `debug_current_class` - Debug the test class in the active buffer
>lua
require('java').test.debug_current_class()
<
- `run_current_method` - Run the test method on the cursor
>lua
require('java').test.run_current_method()
<
- `debug_current_method` - Debug the test method on the cursor
>lua
require('java').test.debug_current_method()
<
- `view_report` - Open the last test report in a popup window
>lua
require('java').test.view_last_report()
<
PROFILES ~
>lua
require('java').profile.ui()
<
REFACTOR ~
- `extract_variable` - Create a variable from value at cursor/selection
>lua
require('java').refactor.extract_variable()
<
- `extract_variable_all_occurrence` - Create a variable for all occurrences from
value at cursor/selection
>lua
require('java').refactor.extract_variable_all_occurrence()
<
- `extract_constant` - Create a constant from the value at cursor/selection
>lua
require('java').refactor.extract_constant()
<
- `extract_method` - Create method from the value at cursor/selection
>lua
require('java').refactor.extract_method()
<
- `extract_field` - Create a field from the value at cursor/selection
>lua
require('java').refactor.extract_field()
<
SETTINGS ~
- `change_runtime` - Change the JDK version to another
>lua
require('java').settings.change_runtime()
<
HOW TO USE JDK X.X VERSION? *nvim-java-how-to-use-jdk-x.x-version?*
:small_orange_diamond:details ~
METHOD 1 ~
Neoconf <https://github.com/folke/neoconf.nvim> can be used to manage LSP
setting including jdtls. Neoconf allows global configuration as well as project
vice configurations. Here is how you can set Jdtls setting on `neoconf.json`
>json
{
"lspconfig": {
"jdtls": {
"java.configuration.runtimes": [
{
"name": "JavaSE-21",
"path": "/opt/jdk-21",
"default": true
}
]
}
}
}
<
METHOD 2 ~
Pass the settings to Jdtls setup.
>lua
require('lspconfig').jdtls.setup({
settings = {
java = {
configuration = {
runtimes = {
{
name = "JavaSE-21",
path = "/opt/jdk-21",
default = true,
}
}
}
}
}
})
<
CONFIGURATION *nvim-java-configuration*
:small_orange_diamond:details ~
For most users changing the default configuration is not necessary. But if you
want, following options are available
>lua
{
-- list of file that exists in root of the project
root_markers = {
'settings.gradle',
'settings.gradle.kts',
'pom.xml',
'build.gradle',
'mvnw',
'gradlew',
'build.gradle',
'build.gradle.kts',
'.git',
},
jdtls = {
version = 'v1.43.0',
},
lombok = {
version = 'nightly',
},
-- load java test plugins
java_test = {
enable = true,
version = '0.43.0',
},
-- load java debugger plugins
java_debug_adapter = {
enable = true,
version = '0.58.1',
},
spring_boot_tools = {
enable = true,
version = '1.59.0',
},
jdk = {
-- install jdk using mason.nvim
auto_install = true,
version = '17.0.2',
},
notifications = {
-- enable 'Configuring DAP' & 'DAP configured' messages on start up
dap = true,
},
-- We do multiple verifications to make sure things are in place to run this
-- plugin
verification = {
-- 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 doing
invalid_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 doing
duplicate_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 setup
invalid_mason_registry = false,
},
}
<
ARCHITECTURE *nvim-java-architecture*
:small_orange_diamond:details ~
Following is the high level idea. Jdtls is the language server nvim-java
communicates with. However, we don’t have all the features we need just in
Jdtls. So, we are loading java-test & java-debug-adapter extensions when we
launch Jdtls. Once the language server is started, we communicate with the
language 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
>text
┌────────────┐ ┌────────────┐
│ │ │ │
│ Neovim │ │ VSCode │
│ │ │ │
└─────▲──────┘ └──────▲─────┘
│ │
│ │
│ │
│ │
┌───────▼───────┐ ┌──────────────▼──────────────┐
│ │ │ │
│ nvim-java │ │ Extension Pack for Java │
│ │ │ │
└───────▲───────┘ └──────────────▲──────────────┘
│ │
│ │
│ │
│ │
│ │
│ ┌───────────┐ │
│ │ │ │
└──────────────► JDTLS ◄────────────┘
│ │
└───▲───▲───┘
│ │
│ │
│ │
│ │
│ │
┌───────────────┐ │ │ ┌────────────────────────┐
│ │ │ │ │ │
│ java-test ◄────────┘ └─────────► java-debug-adapter │
│ │ │ │
└───────────────┘ └────────────────────────┘
<
PROJECTS ACKNOWLEDGEMENT *nvim-java-projects-acknowledgement*
- spring-boot.nvim <https://github.com/JavaHello/spring-boot.nvim> is the one
that starts sts4 & do other necessary `jdtls` `sts4` sync command registration
in `nvim-java`.
- nvim-jdtls <https://github.com/mfussenegger/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 use `nvim-java` alongside `nvim-jdtls`. So remove
`nvim-jdtls` before installing this
==============================================================================
2. Links *nvim-java-links*
1. *Spring*: https://img.shields.io/badge/Spring-6DB33F?style=for-the-badge&logo=spring&logoColor=white
2. *Java*: https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=openjdk&logoColor=white
3. *Gradle*: https://img.shields.io/badge/Gradle-02303A.svg?style=for-the-badge&logo=Gradle&logoColor=white
4. *Apache Maven*: https://img.shields.io/badge/Apache%20Maven-C71A36?style=for-the-badge&logo=Apache%20Maven&logoColor=white
5. *Neovim*: https://img.shields.io/badge/NeoVim-%2357A143.svg?&style=for-the-badge&logo=neovim&logoColor=white
6. *Lua*: https://img.shields.io/badge/lua-%232C2D72.svg?style=for-the-badge&logo=lua&logoColor=white
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
vim:tw=78:ts=8:noet:ft=help:norl: