Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ want, following options are available
-- 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 = true,
},
}
```
Expand Down
8 changes: 7 additions & 1 deletion lua/java/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
---@field java_debug_adapter { enable: boolean }
---@field jdk { auto_install: boolean }
---@field notifications { dap: boolean }
---@field verification { invalid_order: boolean, duplicate_setup_calls: boolean }
---@field verification { invalid_order: boolean, duplicate_setup_calls: boolean, invalid_mason_registry: boolean }
local config = {
-- list of file that exists in root of the project
root_markers = {
Expand Down Expand Up @@ -57,6 +57,12 @@ local config = {
-- 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 = true,
},
}

Expand Down
36 changes: 36 additions & 0 deletions lua/java/startup/mason-registry-check.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
local mason_source = require('mason-registry.sources')

local M = {
JAVA_REG_ID = 'github:nvim-java/mason-registry',
}

function M.is_valid()
local has_reg = false

for reg in mason_source.iter() do
if reg.id == M.JAVA_REG_ID then
has_reg = true
goto continue
end
end

::continue::

if has_reg then
return {
success = true,
continue = true,
}
end

return {
success = false,
continue = false,
message = 'nvim-java mason registry is not added correctly!'
.. '\nThis occurs when mason.nvim configured incorrectly'
.. '\nPlease refer the link below to fix the issue'
.. '\nhttps://github.com/nvim-java/nvim-java/wiki/Q-&-A#no_entry-cannot-find-package-xxxxx',
}
end

return M
7 changes: 7 additions & 0 deletions lua/java/startup/startup-check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ local function get_checkers()
local config = vim.g.nvim_java_config
local checks = {}

if config.verification.invalid_mason_registry then
table.insert(
checks,
select(1, require('java.startup.mason-registry-check'))
)
end

if config.verification.invalid_order then
table.insert(checks, select(1, require('java.startup.exec-order-check')))
end
Expand Down