pull/1708/head
Oluwatobi 3 months ago
parent b64cf5e3ce
commit 8bad3cd11c

@ -33,7 +33,6 @@ capabilities.textDocument.foldingRange = {
lineFoldingOnly = true, lineFoldingOnly = true,
} }
require('java').setup()
require('lspconfig').jdtls.setup { require('lspconfig').jdtls.setup {
on_attach = on_attach, on_attach = on_attach,
capabilities = capabilities, capabilities = capabilities,

@ -1,111 +1,64 @@
-- Java Language Server configuration.
-- Locations:
-- 'nvim/ftplugin/java.lua'.
-- 'nvim/lang-servers/intellij-java-google-style.xml'
local jdtls_ok, jdtls = pcall(require, 'jdtls') local jdtls_ok, jdtls = pcall(require, 'jdtls')
if not jdtls_ok then if not jdtls_ok then
vim.notify 'JDTLS not found, install with `:LspInstall jdtls`' vim.notify 'JDTLS not found, install with `:MasonInstall jdtls`'
return return
end end
-- See `:help vim.lsp.start_client` for an overview of the supported `config` options. -- Path setup
-- local jdtls_path = vim.fn.stdpath 'data' .. '/mason/packages/jdtls' local jdtls_path = vim.fn.stdpath('data') .. '/mason/packages/jdtls'
local jdtls_path = '/Users/oluwatobibello/.local/share/nvim/mason/packages/jdtls'
local path_to_lsp_server = jdtls_path .. '/config_mac' local path_to_lsp_server = jdtls_path .. '/config_mac'
local path_to_plugins = jdtls_path .. '/plugins/' local path_to_plugins = jdtls_path .. '/plugins/'
local path_to_jar = path_to_plugins .. 'org.eclipse.equinox.launcher_*.jar' local path_to_jar = vim.fn.glob(path_to_plugins .. 'org.eclipse.equinox.launcher_*.jar')
local lombok_path = path_to_plugins .. 'lombok.jar' local lombok_path = vim.fn.glob(path_to_plugins .. 'lombok.jar')
local root_markers = { '.git', 'mvnw', 'gradlew', 'pom.xml', 'build.gradle' } -- Java home directories
local root_dir = require('jdtls.setup').find_root(root_markers) local java_17_home = '/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home'
if root_dir == '' then
return -- Root directory detection
end local root_dir = require('jdtls.setup').find_root({'.git', 'mvnw', 'gradlew', 'pom.xml', 'build.gradle'})
if root_dir == '' then return end
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t') -- Workspace setup
local workspace_dir = vim.fn.stdpath 'data' .. '/site/java/workspace-root/' .. project_name local project_name = vim.fn.fnamemodify(root_dir, ':p:h:t')
os.execute('mkdir ' .. workspace_dir) local workspace_dir = vim.fn.stdpath('data') .. '/site/java/workspace-root/' .. project_name
vim.fn.mkdir(workspace_dir, 'p')
local java_21_home_dir = '/Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home/bin/java' print(workspace_dir)
local java_17_home_dir = '/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home'
local java_11_home_dir = '/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home'
-- Main Config -- Main Config
local config = { local config = {
-- The command that starts the language server
-- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line
cmd = { cmd = {
java_21_home_dir .. '/bin/java', java_17_home .. '/bin/java',
'-Declipse.application=org.eclipse.jdt.ls.core.id1', '-Declipse.application=org.eclipse.jdt.ls.core.id1',
'-Dosgi.bundles.defaultStartLevel=4', '-Dosgi.bundles.defaultStartLevel=4',
'-Declipse.product=org.eclipse.jdt.ls.core.product', '-Declipse.product=org.eclipse.jdt.ls.core.product',
'-Dlog.protocol=true', '-Dlog.protocol=true',
'-Xmx1g',
'-Dlog.level=ALL', '-Dlog.level=ALL',
'--add-modules=ALL-SYSTEM',
'--add-opens',
'java.base/java.util=ALL-UNNAMED',
'--add-opens',
'java.base/java.lang=ALL-UNNAMED',
'-javaagent:' .. lombok_path,
'-Xms1g', '-Xms1g',
'--add-modules=ALL-SYSTEM', '--add-modules=ALL-SYSTEM',
'--add-opens', '--add-opens', 'java.base/java.util=ALL-UNNAMED',
'java.base/java.util=ALL-UNNAMED', '--add-opens', 'java.base/java.lang=ALL-UNNAMED',
'--add-opens', '-javaagent:' .. lombok_path,
'java.base/java.lang=ALL-UNNAMED', '-jar', path_to_jar,
'-configuration', path_to_lsp_server,
'-jar', '-data', workspace_dir,
path_to_jar,
'-configuration',
path_to_lsp_server,
'-data',
workspace_dir,
}, },
-- This is the default if not provided, you can remove it. Or adjust as needed.
-- One dedicated LSP server & client will be started per unique root_dir
root_dir = root_dir, root_dir = root_dir,
-- Here you can configure eclipse.jdt.ls specific settings
-- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
-- for a list of options
settings = { settings = {
java = { java = {
home = java_21_home_dir, eclipse = { downloadSources = true },
eclipse = { maven = { downloadSources = true },
downloadSources = true, implementationsCodeLens = { enabled = true },
}, referencesCodeLens = { enabled = true },
references = { includeDecompiledSources = true },
configuration = { configuration = {
updateBuildConfiguration = 'interactive', updateBuildConfiguration = 'interactive',
runtimes = { runtimes = {
{ { name = 'JavaSE-17', path = java_17_home, default = true }
name = 'JavaSE-21', }
path = java_21_home_dir, }
},
{
name = 'JavaSE-11',
path = java_11_home_dir,
},
{
name = 'JavaSE-17',
path = java_17_home_dir,
},
},
},
maven = {
downloadSources = true,
},
implementationsCodeLens = {
enabled = true,
},
referencesCodeLens = {
enabled = true,
},
references = {
includeDecompiledSources = true,
},
}, },
signatureHelp = { enabled = true }, signatureHelp = { enabled = true },
completion = { completion = {
@ -117,49 +70,21 @@ local config = {
'java.util.Objects.requireNonNull', 'java.util.Objects.requireNonNull',
'java.util.Objects.requireNonNullElse', 'java.util.Objects.requireNonNullElse',
'org.mockito.Mockito.*', 'org.mockito.Mockito.*',
}, }
importOrder = { }
'com',
'java',
'jarkata',
'javax',
'org',
},
},
sources = {
organizeImports = {
starThreshold = 9999,
staticStarThreshold = 9999,
},
},
codeGeneration = {
toString = {
template = '${object.className}{${member.name()}=${member.value}, ${otherMembers}}',
},
useBlocks = true,
},
}, },
flags = { flags = { allow_incremental_sync = true },
allow_incremental_sync = true, init_options = { bundles = {} }
},
init_options = {
bundles = {},
},
} }
config['on_attach'] = function(_, bufnr) -- Keymaps setup
require('keymaps').map_java_keys(bufnr) config.on_attach = function(_, bufnr)
require('lsp_signature').on_attach({ -- Your keymaps here
bind = true, -- This is mandatory, otherwise border config won't get registered. vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, { buffer = bufnr })
floating_window_above_cur_line = false, vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { buffer = bufnr })
padding = '', -- Add other keymaps from your deleted nvim-java-config
handler_opts = {
border = 'rounded',
},
}, bufnr)
end end
-- This starts a new client & server, -- Start JDTLS
-- or attaches to an existing client & server depending on the `root_dir`. jdtls.start_or_attach(config)
require('jdtls').start_or_attach(config)

Loading…
Cancel
Save