1 +local want = require 'std.want'
5 + 'nvim-lsp-installer',
6 +}(function(jdtls, zero, installer)
7 + local debug_log = true
8 + local syntax_server = false
9 + local project = require 'std.project'
10 + local home = os.getenv 'HOME'
12 + local jdtls_root_dir = project.determine_java_project_root '~'
13 + if jdtls_root_dir then
14 + vim.notify('eclipse.jdt.ls java project root is ' .. jdtls_root_dir)
15 + -- even when a project root as found, it does not necessarily mean it is a
16 + -- `classic` java project, in the sense that eclipse.jdt.ls thinks of a "project"
17 + if not project.is_java_project_root(jdtls_root_dir, home) then
18 + -- support for single file mode
19 + syntax_server = true
22 + vim.notify('no root directory for eclipse.jdt.ls could be found.', 'warning')
23 + -- support for single file mode
24 + syntax_server = true
27 + if syntax_server then
28 + vim.notify 'starting eclipse.jdt.ls in syntaxserver mode'
31 + local installed, jdtls_installer = installer.get_server 'jdtls'
32 + if not installed then
33 + vim.notify('jdtls is not installed!', error)
36 + local jdtls_install_dir = jdtls_installer.root_dir
37 + local jdtls_config_dir = nil
38 + local jdtls_syntax_server_config_dir = nil
39 + if vim.fn.has 'mac' == 1 then
40 + jdtls_config_dir = jdtls_install_dir .. '/config_mac'
41 + jdtls_syntax_server_config_dir = jdtls_install_dir .. '/config_ss_mac'
42 + elseif vim.fn.has 'unix' == 1 then
43 + jdtls_config_dir = jdtls_install_dir .. '/config_linux'
44 + jdtls_syntax_server_config_dir = jdtls_install_dir .. '/config_ss_linux'
45 + elseif vim.fn.has 'win32' == 1 then
46 + jdtls_config_dir = jdtls_install_dir .. '/config_win'
47 + jdtls_syntax_server_config_dir = jdtls_install_dir .. '/config_ss_win'
49 + vim.notify('eclipse.jdt.ls cannot be configured for current system.', 'error')
53 + local project_directory
54 + if jdtls_root_dir ~= nil then
55 + project_directory = jdtls_root_dir
57 + project_directory = vim.fn.getcwd()
59 + local project_name = vim.fn.fnamemodify(project_directory, ':p:h:t')
60 + local nvim_data = vim.fn.stdpath 'data'
61 + local jdtls_workspace_dir = nvim_data .. '/eclipse.jdt.ls.workspace/' .. project_name
62 + vim.fn.mkdir(jdtls_workspace_dir, 'p')
64 + local shared_configuration
65 + if syntax_server then
66 + shared_configuration = jdtls_syntax_server_config_dir
68 + shared_configuration = jdtls_config_dir
70 + -- sometimes the jdtls cannot start (code 13).
71 + -- it seems to have to do with invalif configuration "config_linux" and/or "~/.config/jdtls"
72 + local jdtls_command = {
74 + '-Dsyntaxserver=' .. tostring(syntax_server),
75 + '-Declipse.application=org.eclipse.jdt.ls.core.id1',
76 + '-Dosgi.bundles.defaultStartLevel=4',
77 + '-Declipse.product=org.eclipse.jdt.ls.core.product',
78 + '-Dlog.protocol=' .. tostring(debug_log),
80 + '-XX:+UnlockExperimentalVMOptions',
82 + -- '-XX:+UseParallelGC',
83 + -- '-XX:GCTimeRatio=4',
84 + -- '-XX:AdaptiveSizePolicyWeight=90',
85 + '-Dsun.zip.disableMemoryMapping=true',
86 + '-Djava.import.generatesMetadataFilesAtProjectRoot=false',
89 + '--add-modules=ALL-SYSTEM',
91 + 'java.base/java.util=ALL-UNNAMED',
93 + 'java.base/java.lang=ALL-UNNAMED',
95 + vim.fn.glob(jdtls_install_dir .. '/plugins/org.eclipse.equinox.launcher_*.jar', false, false),
97 + shared_configuration,
99 + jdtls_workspace_dir,
102 + -- FIXME: what's this? necessary?
103 + local extendedClientCapabilities = jdtls.extendedClientCapabilities
104 + extendedClientCapabilities.resolveAdditionalTextEditsSupport = true
106 + local server_trace = 'off'
108 + server_trace = 'verbose'
111 + -- See `:help vim.lsp.start_client` for an overview of the supported `config` options.
113 + -- The command that starts the language server
114 + -- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line
115 + cmd = jdtls_command,
117 + -- This is the default if not provided, you can remove it. Or adjust as needed.
118 + -- One dedicated LSP server & client will be started per unique root_dir
119 + root_dir = jdtls_root_dir,
121 + -- Here you can configure eclipse.jdt.ls specific settings
122 + -- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
123 + -- for a list of options
128 + organizeImports = {
129 + starThreshold = 9999,
130 + staticStarThreshold = 9999,
134 + generateComments = true,
135 + hashCodeEquals = { useJava7Objects = true, useInstanceOf = true },
136 + -- insertionLocation = '',
138 + listArrayContents = true,
139 + skipNullValues = false,
145 + favoriteStaticMembers = {
146 + 'org.hamcrest.MatcherAssert.assertThat',
147 + 'org.hamcrest.Matchers.*',
148 + 'org.hamcrest.CoreMatchers.*',
149 + 'org.junit.jupiter.api.Assertions.*',
150 + 'java.util.Objects.requireNonNull',
151 + 'java.util.Objects.requireNonNullElse',
152 + 'org.mockito.Mockito.*',
159 + guessMethodArguments = false,
173 + --FIXME: configure platforms per host
176 + name = 'JavaSE-1.8',
177 + path = '/usr/lib/jvm/java-8-openjdk-amd64',
180 + name = 'JavaSE-11',
181 + path = '/usr/lib/jvm/java-11-openjdk-amd64',
184 + name = 'JavaSE-17',
185 + path = '/usr/lib/jvm/java-17-openjdk-amd64',
189 + updateBuildConfiguration = 'automatic',
191 + eclipse = { downloadSources = true },
192 + errors = { incompleteClasspath = { severity = 'warning' } },
193 + foldingRange = false,
198 + implementationsCodeLens = true,
199 + inlayhints = { parameterNames = true },
200 + maven = { downloadSources = true, updateSnapshots = false },
201 + maxConcurrentBuilds = 8,
202 + referenceCodeLens = true,
204 + saveActions = { organizeImports = true },
205 + selectionRange = true,
206 + signatureHelp = true,
207 + trace = { server = server_trace },
211 + -- Language server `initializationOptions`
212 + -- You need to extend the `bundles` with paths to jar files
213 + -- if you want to use additional eclipse.jdt.ls plugins.
215 + -- See https://github.com/mfussenegger/nvim-jdtls#java-debug-installation
217 + -- If you don't plan on using the debugger or other eclipse.jdt.ls plugins you can remove this
219 + -- TODO: integrate debug and test extensions. can those be installed via paq, even though they are not vim plugins?
221 + extendedClientCapabilities = extendedClientCapabilities,
224 + debounce_text_changes = 80,
225 + allow_incremental_sync = true,
228 + -- This starts a new client & server,
229 + -- or attaches to an existing client & server depending on the `root_dir`.
230 + local merged_config = zero.build_options('jdtls', config)
231 + jdtls.start_or_attach(merged_config)