From c02e65574539e7fbe0f5856a431e5ab950f10a88 Mon Sep 17 00:00:00 2001 From: s1n7ax Date: Sun, 16 Feb 2025 17:16:04 +0530 Subject: [PATCH 1/2] fix: nvim-java mason reg is added if the mason config does not consider parent conf --- README.md | 158 +++++++++++++++++---------------- lazy.lua | 12 +-- lua/java/config.lua | 9 ++ lua/java/startup/mason-dep.lua | 10 +++ 4 files changed, 108 insertions(+), 81 deletions(-) diff --git a/README.md b/README.md index b2bce7f..a6cc10e 100644 --- a/README.md +++ b/README.md @@ -341,81 +341,89 @@ 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, - }, +local config = { + -- 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.40.1', + }, + + -- load java debugger plugins + java_debug_adapter = { + enable = true, + version = '0.58.1', + }, + + spring_boot_tools = { + enable = true, + version = '1.55.1', + }, + + 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, + }, + + mason = { + -- These mason registries will be prepended to the existing mason + -- configuration + registries = { + 'github:nvim-java/mason-registry', + }, + }, } ``` diff --git a/lazy.lua b/lazy.lua index 90e58b3..a352b8d 100644 --- a/lazy.lua +++ b/lazy.lua @@ -15,12 +15,12 @@ return { }, { 'williamboman/mason.nvim', - opts = { - registries = { - 'github:nvim-java/mason-registry', - 'github:mason-org/mason-registry', - }, - }, + -- opts = { + -- registries = { + -- 'github:nvim-java/mason-registry', + -- 'github:mason-org/mason-registry', + -- }, + -- }, }, }, } diff --git a/lua/java/config.lua b/lua/java/config.lua index beb552e..7383646 100644 --- a/lua/java/config.lua +++ b/lua/java/config.lua @@ -8,6 +8,7 @@ ---@field jdk { auto_install: boolean, version: string } ---@field notifications { dap: boolean } ---@field verification { invalid_order: boolean, duplicate_setup_calls: boolean, invalid_mason_registry: boolean } +---@field mason { registries: string[] } local config = { -- list of file that exists in root of the project root_markers = { @@ -83,6 +84,14 @@ local config = { -- will stop setup invalid_mason_registry = false, }, + + mason = { + -- These mason registries will be prepended to the existing mason + -- configuration + registries = { + 'github:nvim-java/mason-registry', + }, + }, } return config diff --git a/lua/java/startup/mason-dep.lua b/lua/java/startup/mason-dep.lua index f05e3a5..2e00762 100644 --- a/lua/java/startup/mason-dep.lua +++ b/lua/java/startup/mason-dep.lua @@ -1,6 +1,7 @@ local log = require('java.utils.log') local mason_ui = require('mason.ui') local mason_util = require('java.utils.mason') +local list_util = require('java-core.utils.list') local notify = require('java-core.utils.notify') local async = require('java-core.utils.async') local lazy = require('java.ui.lazy') @@ -13,6 +14,15 @@ local M = {} ---Install mason package dependencies for nvim-java ---@param config java.Config function M.install(config) + local mason_default_config = require('mason.settings').current + + local registries = list_util + :new(config.mason.registries) + :concat(mason_default_config.registries) + + require('mason').setup({ + registries = registries, + }) local packages = M.get_pkg_list(config) local is_outdated = mason_util.is_outdated(packages) From cc87c6cdc82231a2548832d7f83a33e99f61f6a3 Mon Sep 17 00:00:00 2001 From: s1n7ax Date: Sun, 16 Feb 2025 17:17:38 +0530 Subject: [PATCH 2/2] chore: format the config example --- README.md | 167 +++++++++++++++++++++++++++--------------------------- 1 file changed, 84 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index a6cc10e..3e2328c 100644 --- a/README.md +++ b/README.md @@ -341,90 +341,91 @@ For most users changing the default configuration is not necessary. But if you want, following options are available ```lua -local config = { - -- 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.40.1', - }, - - -- load java debugger plugins - java_debug_adapter = { - enable = true, - version = '0.58.1', - }, - - spring_boot_tools = { - enable = true, - version = '1.55.1', - }, - - 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, - }, - - mason = { - -- These mason registries will be prepended to the existing mason - -- configuration - registries = { - 'github:nvim-java/mason-registry', - }, - }, +{ + -- 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.40.1', + }, + + -- load java debugger plugins + java_debug_adapter = { + enable = true, + version = '0.58.1', + }, + + spring_boot_tools = { + enable = true, + version = '1.55.1', + }, + + 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, + }, + + mason = { + -- These mason registries will be prepended to the existing mason + -- configuration + registries = { + 'github:nvim-java/mason-registry', + }, + }, } + ```