-
-
Notifications
You must be signed in to change notification settings - Fork 309
Expand file tree
/
Copy pathinit.lua
More file actions
154 lines (151 loc) · 5.45 KB
/
init.lua
File metadata and controls
154 lines (151 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
return {
{ import = "astrocommunity.pack.xml" },
{
"nvim-treesitter/nvim-treesitter",
optional = true,
opts = function(_, opts)
if opts.ensure_installed ~= "all" then
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "java" })
end
end,
},
{
"williamboman/mason-lspconfig.nvim",
optional = true,
opts = function(_, opts)
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "jdtls" })
end,
},
{
"jay-babu/mason-nvim-dap.nvim",
optional = true,
opts = function(_, opts)
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "javadbg", "javatest" })
end,
},
{
"WhoIsSethDaniel/mason-tool-installer.nvim",
optional = true,
opts = function(_, opts)
opts.ensure_installed =
require("astrocore").list_insert_unique(opts.ensure_installed, { "jdtls", "java-debug-adapter", "java-test" })
end,
},
{
"mfussenegger/nvim-jdtls",
ft = { "java" },
dependencies = {
"williamboman/mason-lspconfig.nvim",
{
"AstroNvim/astrolsp",
optional = true,
---@type AstroLSPOpts
opts = {
---@diagnostic disable: missing-fields
handlers = { jdtls = false },
},
},
},
opts = function(_, opts)
local utils = require "astrocore"
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
local workspace_dir = vim.fn.stdpath "data" .. "/site/java/workspace-root/" .. project_name
vim.fn.mkdir(workspace_dir, "p")
if not (vim.fn.has "mac" == 1 or vim.fn.has "unix" == 1 or vim.fn.has "win32" == 1) then
utils.notify("jdtls: Could not detect valid OS", vim.log.levels.ERROR)
end
return utils.extend_tbl({
cmd = {
"java",
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
"-Dosgi.bundles.defaultStartLevel=4",
"-Declipse.product=org.eclipse.jdt.ls.core.product",
"-Dlog.protocol=true",
"-Dlog.level=ALL",
"-javaagent:" .. vim.fn.expand "$MASON/share/jdtls/lombok.jar",
"-Xms1g",
"--add-modules=ALL-SYSTEM",
"--add-opens",
"java.base/java.util=ALL-UNNAMED",
"--add-opens",
"java.base/java.lang=ALL-UNNAMED",
"-jar",
vim.fn.expand "$MASON/share/jdtls/plugins/org.eclipse.equinox.launcher.jar",
"-configuration",
vim.fn.expand "$MASON/share/jdtls/config",
"-data",
workspace_dir,
},
root_dir = vim.fs.root(0, { ".git", "mvnw", "gradlew" }),
settings = {
java = {
eclipse = { downloadSources = true },
configuration = { updateBuildConfiguration = "interactive" },
maven = { downloadSources = true },
implementationsCodeLens = { enabled = true },
referencesCodeLens = { enabled = true },
inlayHints = { parameterNames = { enabled = "all" } },
signatureHelp = { enabled = true },
completion = {
favoriteStaticMembers = {
"org.hamcrest.MatcherAssert.assertThat",
"org.hamcrest.Matchers.*",
"org.hamcrest.CoreMatchers.*",
"org.junit.jupiter.api.Assertions.*",
"java.util.Objects.requireNonNull",
"java.util.Objects.requireNonNullElse",
"org.mockito.Mockito.*",
},
},
sources = {
organizeImports = {
starThreshold = 9999,
staticStarThreshold = 9999,
},
},
},
},
init_options = {
bundles = {
vim.fn.expand "$MASON/share/java-debug-adapter/com.microsoft.java.debug.plugin.jar",
-- unpack remaining bundles
(table.unpack or unpack)(vim.split(vim.fn.glob "$MASON/share/java-test/*.jar", "\n", {})),
},
},
handlers = {
["$/progress"] = function() end, -- disable progress updates.
},
filetypes = { "java" },
on_attach = function(...)
require("jdtls").setup_dap { hotcodereplace = "auto" }
local astrolsp_avail, astrolsp = pcall(require, "astrolsp")
if astrolsp_avail then astrolsp.on_attach(...) end
end,
}, opts)
end,
config = function(_, opts)
-- setup autocmd on filetype detect java
vim.api.nvim_create_autocmd("Filetype", {
pattern = "java", -- autocmd to start jdtls
callback = function()
if opts.root_dir and opts.root_dir ~= "" then
require("jdtls").start_or_attach(opts)
else
require("astrocore").notify("jdtls: root_dir not found. Please specify a root marker", vim.log.levels.ERROR)
end
end,
})
-- create autocmd to load main class configs on LspAttach.
-- This ensures that the LSP is fully attached.
-- See https://github.com/mfussenegger/nvim-jdtls#nvim-dap-configuration
vim.api.nvim_create_autocmd("LspAttach", {
pattern = "*.java",
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
-- ensure that only the jdtls client is activated
if client.name == "jdtls" then require("jdtls.dap").setup_dap_main_class_configs() end
end,
})
end,
},
}