Skip to content

Commit ef7597d

Browse files
authored
feat: add mason registry check (nvim-java#225)
1 parent 26b3d3f commit ef7597d

4 files changed

Lines changed: 56 additions & 1 deletion

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@ want, following options are available
316316
-- Set following property value to false to disable the notification if
317317
-- you know what you are doing
318318
duplicate_setup_calls = true,
319+
320+
-- nvim-java checks if nvim-java/mason-registry is added correctly to
321+
-- mason.nvim plugin.
322+
-- IF it's not registered correctly, an error will be thrown and nvim-java
323+
-- will stop setup
324+
invalid_mason_registry = true,
319325
},
320326
}
321327
```

lua/java/config.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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 }
7+
---@field verification { invalid_order: boolean, duplicate_setup_calls: boolean, invalid_mason_registry: boolean }
88
local config = {
99
-- list of file that exists in root of the project
1010
root_markers = {
@@ -57,6 +57,12 @@ local config = {
5757
-- Set following property value to false to disable the notification if
5858
-- you know what you are doing
5959
duplicate_setup_calls = true,
60+
61+
-- nvim-java checks if nvim-java/mason-registry is added correctly to
62+
-- mason.nvim plugin.
63+
-- IF it's not registered correctly, an error will be thrown and nvim-java
64+
-- will stop setup
65+
invalid_mason_registry = true,
6066
},
6167
}
6268

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
local mason_source = require('mason-registry.sources')
2+
3+
local M = {
4+
JAVA_REG_ID = 'github:nvim-java/mason-registry',
5+
}
6+
7+
function M.is_valid()
8+
local has_reg = false
9+
10+
for reg in mason_source.iter() do
11+
if reg.id == M.JAVA_REG_ID then
12+
has_reg = true
13+
goto continue
14+
end
15+
end
16+
17+
::continue::
18+
19+
if has_reg then
20+
return {
21+
success = true,
22+
continue = true,
23+
}
24+
end
25+
26+
return {
27+
success = false,
28+
continue = false,
29+
message = 'nvim-java mason registry is not added correctly!'
30+
.. '\nThis occurs when mason.nvim configured incorrectly'
31+
.. '\nPlease refer the link below to fix the issue'
32+
.. '\nhttps://github.com/nvim-java/nvim-java/wiki/Q-&-A#no_entry-cannot-find-package-xxxxx',
33+
}
34+
end
35+
36+
return M

lua/java/startup/startup-check.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ local function get_checkers()
55
local config = vim.g.nvim_java_config
66
local checks = {}
77

8+
if config.verification.invalid_mason_registry then
9+
table.insert(
10+
checks,
11+
select(1, require('java.startup.mason-registry-check'))
12+
)
13+
end
14+
815
if config.verification.invalid_order then
916
table.insert(checks, select(1, require('java.startup.exec-order-check')))
1017
end

0 commit comments

Comments
 (0)