-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathjava.lua
149 lines (147 loc) · 5.44 KB
/
java.lua
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
local jdtls = require('jdtls')
local root_markers = {'gradlew', '.git'}
local root_dir = require('jdtls.setup').find_root(root_markers)
local home = os.getenv('HOME')
local workspace_folder = home .. "/.local/share/eclipse/" .. vim.fn.fnamemodify(root_dir, ":p:h:t")
local config = require('me.lsp.conf').mk_config()
config.settings = {
java = {
signatureHelp = { enabled = true };
contentProvider = { preferred = 'fernflower' };
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.*"
},
filteredTypes = {
"com.sun.*",
"io.micrometer.shaded.*",
"java.awt.*",
"jdk.*",
"sun.*",
},
};
sources = {
organizeImports = {
starThreshold = 9999;
staticStarThreshold = 9999;
};
};
codeGeneration = {
toString = {
template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}"
},
hashCodeEquals = {
useJava7Objects = true,
},
useBlocks = true,
};
configuration = {
runtimes = {
{
name = "JavaSE-1.8",
path = "/usr/lib/jvm/java-8-openjdk/",
},
{
name = "JavaSE-11",
path = "/usr/lib/jvm/java-11-openjdk/",
},
{
name = "JavaSE-16",
path = home .. "/.local/jdks/jdk-16.0.1+9/",
},
{
name = "JavaSE-17",
path = home .. "/.local/jdks/jdk-17.0.2+8/",
},
}
};
};
}
config.cmd = {
home .. "/.local/jdks/jdk-17.0.2+8/bin/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',
'-Xmx4g',
'--add-modules=ALL-SYSTEM',
'--add-opens', 'java.base/java.util=ALL-UNNAMED',
'--add-opens', 'java.base/java.lang=ALL-UNNAMED',
'-jar', vim.fn.glob(home .. '/dev/eclipse/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/plugins/org.eclipse.equinox.launcher_*.jar'),
'-configuration', home .. '/dev/eclipse/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/config_linux',
'-data', workspace_folder,
}
config.on_attach = function(client, bufnr)
require('me.lsp.conf').on_attach(client, bufnr, {
server_side_fuzzy_completion = true,
})
jdtls.setup_dap({hotcodereplace = 'auto'})
jdtls.setup.add_commands()
local opts = { silent = true, buffer = bufnr }
vim.keymap.set('n', "<A-o>", jdtls.organize_imports, opts)
vim.keymap.set('n', "<leader>df", jdtls.test_class, opts)
vim.keymap.set('n', "<leader>dn", jdtls.test_nearest_method, opts)
vim.keymap.set('n', "crv", jdtls.extract_variable, opts)
vim.keymap.set('v', 'crm', [[<ESC><CMD>lua require('jdtls').extract_method(true)<CR>]], opts)
vim.keymap.set('n', "crc", jdtls.extract_constant, opts)
local create_command = vim.api.nvim_buf_create_user_command
create_command(bufnr, 'W', require('me.lsp.ext').remove_unused_imports, {
nargs = 0,
})
end
local jar_patterns = {
'/dev/microsoft/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar',
'/dev/dgileadi/vscode-java-decompiler/server/*.jar',
'/dev/microsoft/vscode-java-test/java-extension/com.microsoft.java.test.plugin/target/*.jar',
'/dev/microsoft/vscode-java-test/java-extension/com.microsoft.java.test.runner/target/*.jar',
'/dev/microsoft/vscode-java-test/java-extension/com.microsoft.java.test.runner/lib/*.jar',
'/dev/testforstephen/vscode-pde/server/*.jar'
}
-- npm install broke for me: https://github.com/npm/cli/issues/2508
-- So gather the required jars manually; this is based on the gulpfile.js in the vscode-java-test repo
local plugin_path = '/dev/microsoft/vscode-java-test/java-extension/com.microsoft.java.test.plugin.site/target/repository/plugins/'
local bundle_list = vim.tbl_map(
function(x) return require('jdtls.path').join(plugin_path, x) end,
{
'org.eclipse.jdt.junit4.runtime_*.jar',
'org.eclipse.jdt.junit5.runtime_*.jar',
'org.junit.jupiter.api*.jar',
'org.junit.jupiter.engine*.jar',
'org.junit.jupiter.migrationsupport*.jar',
'org.junit.jupiter.params*.jar',
'org.junit.vintage.engine*.jar',
'org.opentest4j*.jar',
'org.junit.platform.commons*.jar',
'org.junit.platform.engine*.jar',
'org.junit.platform.launcher*.jar',
'org.junit.platform.runner*.jar',
'org.junit.platform.suite.api*.jar',
'org.apiguardian*.jar'
}
)
vim.list_extend(jar_patterns, bundle_list)
local bundles = {}
for _, jar_pattern in ipairs(jar_patterns) do
for _, bundle in ipairs(vim.split(vim.fn.glob(home .. jar_pattern), '\n')) do
if not vim.endswith(bundle, 'com.microsoft.java.test.runner-jar-with-dependencies.jar')
and not vim.endswith(bundle, 'com.microsoft.java.test.runner.jar') then
table.insert(bundles, bundle)
end
end
end
local extendedClientCapabilities = jdtls.extendedClientCapabilities;
extendedClientCapabilities.resolveAdditionalTextEditsSupport = true;
config.init_options = {
bundles = bundles;
extendedClientCapabilities = extendedClientCapabilities;
}
-- mute; having progress reports is enough
config.handlers['language/status'] = function() end
jdtls.start_or_attach(config)