From 1757cb319e9a20d0c338134bdc74473c4746b4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Mon, 6 Jun 2022 19:35:17 +0200 Subject: [PATCH] Add neovim-java-plugin-host --- .../config/nvim/lua/esensar/init/plugins.lua | 1 + .../nvim/lua/esensar/lsp/jdtls_setup.lua | 29 ++++++++++++++++--- symlinks/config/nvim/plugin/java_host.lua | 13 +++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 symlinks/config/nvim/plugin/java_host.lua diff --git a/symlinks/config/nvim/lua/esensar/init/plugins.lua b/symlinks/config/nvim/lua/esensar/init/plugins.lua index 3006767..089bd2c 100644 --- a/symlinks/config/nvim/lua/esensar/init/plugins.lua +++ b/symlinks/config/nvim/lua/esensar/init/plugins.lua @@ -48,6 +48,7 @@ return require("packer").startup({ use("diepm/vim-rest-console") -- REST console for vim use("esensar/nvim-dev-container") -- devcontainer.json support use("jbyuki/one-small-step-for-vimkind") -- Debugger for Nvim-Lua + use("esensar/neovim-java-plugin-host") -- Host for Java plugins -- Snippets use("L3MON4D3/LuaSnip") -- snippets support diff --git a/symlinks/config/nvim/lua/esensar/lsp/jdtls_setup.lua b/symlinks/config/nvim/lua/esensar/lsp/jdtls_setup.lua index f05c260..5dacb5b 100644 --- a/symlinks/config/nvim/lua/esensar/lsp/jdtls_setup.lua +++ b/symlinks/config/nvim/lua/esensar/lsp/jdtls_setup.lua @@ -5,15 +5,29 @@ local common_config = require("esensar.lsp.server_config") local M = {} +local function is_in_config_home(bufname) + bufname = bufname or vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf()) + local dirname = vim.fn.fnamemodify(bufname, ":p:h") + local getparent = function(p) + return vim.fn.fnamemodify(p, ":h") + end + local config_path = vim.fn.resolve(vim.fn.expand(vim.fn.stdpath("config"))) + while getparent(dirname) ~= dirname do + if dirname == config_path then + return true + else + dirname = getparent(dirname) + end + end + return false +end + function M.setup() local _, installed_jdtls = require("nvim-lsp-installer.servers").get_server("jdtls") require("jdtls").setup_dap({ hotcoredeplace = "auto" }) require("jdtls.setup").add_commands() - local root_markers = { "gradlew", "pom.xml" } - local root_dir = require("jdtls.setup").find_root(root_markers) - local config = vim.tbl_extend("force", installed_jdtls["_default_options"], { flags = { allow_incremental_sync = true, @@ -31,7 +45,14 @@ function M.setup() }, }, } - config.root_dir = root_dir + + if is_in_config_home() then + config.settings.java.project = { + referencedLibraries = require("java_plugin_host").classpath, + } + end + config.root_dir = require("jdtls.setup").find_root({ "gradlew", "pom.xml" }) + config.on_init = function(client, _) client.notify("workspace/didChangeConfiguration", { settings = config.settings }) end diff --git a/symlinks/config/nvim/plugin/java_host.lua b/symlinks/config/nvim/plugin/java_host.lua new file mode 100644 index 0000000..b230250 --- /dev/null +++ b/symlinks/config/nvim/plugin/java_host.lua @@ -0,0 +1,13 @@ +-- Configuration for Java remote plugin host +require("java_plugin_host").setup({ + autostart = false, + rplugins = { + load_class = true, + compile_java = true, + }, + common_host = { + custom_repositories = { + "https://maven.pkg.github.com/OWNER/REPOSITORY", + }, + }, +})