File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -264,38 +264,58 @@ want, following options are available
264264
265265``` lua
266266{
267- -- list of file that exists in root of the project
268- root_markers = {
269- ' settings.gradle' ,
270- ' settings.gradle.kts' ,
271- ' pom.xml' ,
272- ' build.gradle' ,
273- ' mvnw' ,
274- ' gradlew' ,
275- ' build.gradle' ,
276- ' build.gradle.kts' ,
277- ' .git' ,
278- },
279-
280- -- load java test plugins
281- java_test = {
282- enable = true ,
283- },
284-
285- -- load java debugger plugins
286- java_debug_adapter = {
287- enable = true ,
288- },
289-
290- jdk = {
291- -- install jdk using mason.nvim
292- auto_install = true ,
293- },
294-
295- notifications = {
296- -- enable 'Configuring DAP' & 'DAP configured' messages on start up
297- dap = true ,
298- },
267+ -- list of file that exists in root of the project
268+ root_markers = {
269+ ' settings.gradle' ,
270+ ' settings.gradle.kts' ,
271+ ' pom.xml' ,
272+ ' build.gradle' ,
273+ ' mvnw' ,
274+ ' gradlew' ,
275+ ' build.gradle' ,
276+ ' build.gradle.kts' ,
277+ ' .git' ,
278+ },
279+
280+ -- load java test plugins
281+ java_test = {
282+ enable = true ,
283+ },
284+
285+ -- load java debugger plugins
286+ java_debug_adapter = {
287+ enable = true ,
288+ },
289+
290+ jdk = {
291+ -- install jdk using mason.nvim
292+ auto_install = true ,
293+ },
294+
295+ notifications = {
296+ -- enable 'Configuring DAP' & 'DAP configured' messages on start up
297+ dap = true ,
298+ },
299+
300+ -- We do multiple verifications to make sure things are in place to run this
301+ -- plugin
302+ verification = {
303+ -- nvim-java checks for the order of execution of following
304+ -- * require('java').setup()
305+ -- * require('lspconfig').jdtls.setup()
306+ -- IF they are not executed in the correct order, you will see a error
307+ -- notification.
308+ -- Set following to false to disable the notification if you know what you
309+ -- are doing
310+ invalid_order = true ,
311+
312+ -- nvim-java checks if the require('java').setup() is called multiple
313+ -- times.
314+ -- IF there are multiple setup calls are executed, an error will be shown
315+ -- Set following property value to false to disable the notification if
316+ -- you know what you are doing
317+ duplicate_setup_calls = true ,
318+ },
299319}
300320```
301321
Original file line number Diff line number Diff line change 11local decomple_watch = require (' java.startup.decompile-watcher' )
22local mason_dep = require (' java.startup.mason-dep' )
3- local nvim_dep = require (' java.startup.nvim-dep' )
43local setup_wrap = require (' java.startup.lspconfig-setup-wrap' )
4+ local startup_check = require (' java.startup.startup-check' )
55
66local test = require (' java.api.test' )
77local dap = require (' java.api.dap' )
@@ -16,9 +16,12 @@ local M = {}
1616function M .setup (custom_config )
1717 local config =
1818 vim .tbl_deep_extend (' force' , global_config , custom_config or {})
19+
1920 vim .g .nvim_java_config = config
2021
21- nvim_dep .check ()
22+ if not startup_check () then
23+ return
24+ end
2225
2326 local is_installing = mason_dep .install (config )
2427
Original file line number Diff line number Diff line change 44--- @field java_debug_adapter { enable : boolean }
55--- @field jdk { auto_install : boolean }
66--- @field notifications { dap : boolean }
7+ --- @field verification { invalid_order : boolean , duplicate_setup_calls : boolean }
78local config = {
89 -- list of file that exists in root of the project
910 root_markers = {
@@ -37,6 +38,26 @@ local config = {
3738 -- enable 'Configuring DAP' & 'DAP configured' messages on start up
3839 dap = true ,
3940 },
41+
42+ -- We do multiple verifications to make sure things are in place to run this
43+ -- plugin
44+ verification = {
45+ -- nvim-java checks for the order of execution of following
46+ -- * require('java').setup()
47+ -- * require('lspconfig').jdtls.setup()
48+ -- IF they are not executed in the correct order, you will see a error
49+ -- notification.
50+ -- Set following to false to disable the notification if you know what you
51+ -- are doing
52+ invalid_order = true ,
53+
54+ -- nvim-java checks if the require('java').setup() is called multiple
55+ -- times.
56+ -- IF there are multiple setup calls are executed, an error will be shown
57+ -- Set following property value to false to disable the notification if
58+ -- you know what you are doing
59+ duplicate_setup_calls = true ,
60+ },
4061}
4162
4263return config
Original file line number Diff line number Diff line change 1+ local M = {}
2+
3+ local message = ' require("java").setup() is called more than once'
4+ .. ' \n nvim-java will continue to setup but nvim-java configurations might not work as expected'
5+ .. ' \n This might be due to old installation instructions.'
6+ .. ' \n Please check the latest guide at https://github.com/nvim-java/nvim-java#hammer-how-to-install'
7+ .. ' \n If you know what you are doing, you can disable the check from the config'
8+ .. ' \n https://github.com/nvim-java/nvim-java#wrench-configuration'
9+
10+ function M .is_valid ()
11+ if vim .g .nvim_java_setup_is_called then
12+ return {
13+ success = false ,
14+ continue = true ,
15+ message = message ,
16+ }
17+ end
18+
19+ vim .g .nvim_java_setup_is_called = true
20+
21+ return {
22+ success = true ,
23+ continue = true ,
24+ }
25+ end
26+
27+ return M
Original file line number Diff line number Diff line change 1+ local lspconfig = require (' lspconfig' )
2+
3+ local M = {}
4+
5+ lspconfig .util .on_setup = lspconfig .util .add_hook_before (
6+ lspconfig .util .on_setup ,
7+ function (config )
8+ if config .name == ' jdtls' then
9+ vim .g .nvim_java_jdtls_setup_is_called = true
10+ end
11+ end
12+ )
13+
14+ local message = ' Looks like require("lspconfig").jdtls.setup() is called before require("java").setup().'
15+ .. ' \n nvim-java will continue to setup but most features may not work as expected'
16+ .. ' \n This might be due to old installation instructions.'
17+ .. ' \n Please check the latest guide at https://github.com/nvim-java/nvim-java#hammer-how-to-install'
18+ .. ' \n If you know what you are doing, you can disable the check from the config'
19+ .. ' \n https://github.com/nvim-java/nvim-java#wrench-configuration'
20+
21+ function M .is_valid ()
22+ if vim .g .nvim_java_jdtls_setup_is_called then
23+ return {
24+ success = false ,
25+ continue = true ,
26+ message = message ,
27+ }
28+ end
29+
30+ local clients = vim .lsp .get_clients ({ name = ' jdtls' })
31+
32+ if # clients > 0 then
33+ return {
34+ success = false ,
35+ continue = true ,
36+ message = message ,
37+ }
38+ end
39+
40+ return {
41+ success = true ,
42+ continue = true ,
43+ }
44+ end
45+
46+ return M
Original file line number Diff line number Diff line change 1- local notify = require (' java-core.utils.notify' )
21local log = require (' java.utils.log' )
32
43local pkgs = {
@@ -36,26 +35,33 @@ Please follow the install guide in https://github.com/nvim-java/nvim-java to ins
3635
3736local M = {}
3837
39- function M .check ()
38+ function M .is_valid ()
4039 log .info (' check neovim plugin dependencies' )
41- M .neovim_plugin_check ()
42- end
4340
44- --- @private
45- function M .neovim_plugin_check ()
4641 for _ , pkg in ipairs (pkgs ) do
4742 local ok , _ = pcall (require , pkg .name )
4843
4944 if not ok then
5045 if pkg .warn then
51- log .warn (pkg .warn )
52- notify .warn (pkg .warn )
46+ return {
47+ success = false ,
48+ continue = true ,
49+ message = pkg .warn ,
50+ }
5351 else
54- log .error (pkg .err )
55- error (pkg .err )
52+ return {
53+ success = false ,
54+ continue = false ,
55+ message = pkg .err ,
56+ }
5657 end
5758 end
5859 end
60+
61+ return {
62+ success = true ,
63+ continue = true ,
64+ }
5965end
6066
6167return M
Original file line number Diff line number Diff line change 1+ local log = require (' java.utils.log' )
2+ local notify = require (' java-core.utils.notify' )
3+
4+ local function get_checkers ()
5+ local config = vim .g .nvim_java_config
6+ local checks = {}
7+
8+ if config .verification .invalid_order then
9+ table.insert (checks , select (1 , require (' java.startup.exec-order-check' )))
10+ end
11+
12+ if config .verification .duplicate_setup_calls then
13+ table.insert (
14+ checks ,
15+ select (1 , require (' java.startup.duplicate-setup-check' ))
16+ )
17+ end
18+
19+ table.insert (checks , select (1 , require (' java.startup.nvim-dep' )))
20+
21+ return checks
22+ end
23+
24+ return function ()
25+ local checkers = get_checkers ()
26+
27+ for _ , check in ipairs (checkers ) do
28+ local check_res = check .is_valid ()
29+
30+ if check_res .message then
31+ if not check_res .success then
32+ log .error (check_res .message )
33+ notify .error (check_res .message )
34+ else
35+ log .warn (check_res .message )
36+ notify .warn (check_res .message )
37+ end
38+ end
39+
40+ if not check_res .continue then
41+ return false
42+ end
43+ end
44+
45+ return true
46+ end
You can’t perform that action at this time.
0 commit comments