refactor(nvim): correctly start java lsp when switching projects

chezmoi
sgoudham 2 years ago
parent b401dbb587
commit 83924bfa13
Signed by: hammy
GPG Key ID: 44E818FD5457EEA4

@ -1,2 +1,6 @@
local config = require("lsp.java").make_jdtls_config()
local root_markers = { "gradlew", "mvnw", ".git", "pom.xml", "build.gradle" }
local root_dir = require("jdtls.setup").find_root(root_markers)
local workspace_folder = os.getenv("HOME") .. "/.local/share/eclipse/" .. vim.fn.fnamemodify(root_dir, ":p:h:t")
local config = require("lsp.java").make_jdtls_config(root_dir, workspace_folder)
require("jdtls").start_or_attach(config)

@ -4,9 +4,6 @@ vim.g.mapleader = " "
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.lsp.set_log_level("TRACE")
print(vim.lsp.get_log_path())
-- bootstrap & set up lazy
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then

@ -5,15 +5,6 @@ local SDKMAN_DIR = os.getenv("SDKMAN_DIR")
local lsp = require("lsp")
local jdtls = require("jdtls")
local root_markers = { "gradlew", "mvnw", ".git", "pom.xml", "build.gradle" }
local root_dir = require("jdtls.setup").find_root(root_markers)
-- eclipse.jdt.ls stores project specific data within a folder. If you are working
-- with multiple different projects, each project must use a dedicated data directory.
-- This variable is used to configure eclipse to use the directory name of the
-- current project found using the root_marker as the folder for project specific data.
local workspace_folder = HOME .. "/.local/share/eclipse/" .. vim.fn.fnamemodify(root_dir, ":p:h:t")
local bundles = {}
local mason_path = vim.fn.glob(vim.fn.stdpath("data") .. "/mason/")
vim.list_extend(bundles, vim.split(vim.fn.glob(mason_path .. "packages/java-test/extension/server/*.jar"), "\n"))
@ -58,7 +49,8 @@ local on_attach = function(client, bufnr)
nnoremap("<leader>tm", jdtls.test_nearest_method, bufopts, "Test method (DAP)")
end
local config = {
function M.make_jdtls_config(root_dir, workspace_folder)
return {
flags = {
debounce_text_changes = 80,
allow_incremental_sync = true,
@ -188,9 +180,6 @@ local config = {
workspace_folder,
},
}
function M.make_jdtls_config()
return config
end
return M

@ -51,6 +51,16 @@ return {
pythonPath = get_python_path,
},
}
dap.configurations.java = {
{
type = "java",
request = "attach",
name = "Debug (Attach) - Remote",
hostName = "127.0.0.1",
port = 5005,
},
}
end,
})

Loading…
Cancel
Save