feat(neovim): added nvim-jdtls (will continue to use IntelliJ though!)
This commit is contained in:
@@ -33,6 +33,8 @@
|
||||
"nui.nvim": { "branch": "main", "commit": "61574ce6e60c815b0a0c4b5655b8486ba58089a1" },
|
||||
"nvim-autopairs": { "branch": "master", "commit": "e38c5d837e755ce186ae51d2c48e1b387c4425c6" },
|
||||
"nvim-cmp": { "branch": "main", "commit": "d818fd0624205b34e14888358037fb6f5dc51234" },
|
||||
"nvim-dap": { "branch": "master", "commit": "bc03b83c94d0375145ff5ac6a6dcf28c1241e06f" },
|
||||
"nvim-jdtls": { "branch": "master", "commit": "6bfd1591583b02e742fc3a2f43393c4ea3b6d3c7" },
|
||||
"nvim-lsp-file-operations": { "branch": "master", "commit": "92a673de7ecaa157dd230d0128def10beb56d103" },
|
||||
"nvim-lspconfig": { "branch": "master", "commit": "3cceca5a79b66d735cbacbf05fa0bce5f8b716ca" },
|
||||
"nvim-spectre": { "branch": "master", "commit": "9a28f926d3371b7ef02243cbbb653a0478d06e31" },
|
||||
@@ -48,6 +50,7 @@
|
||||
"telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" },
|
||||
"telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" },
|
||||
"telescope.nvim": { "branch": "master", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" },
|
||||
"tiny-inline-diagnostic.nvim": { "branch": "main", "commit": "4b5bc565d8ea4dce4bc45bba57f292578ba5197c" },
|
||||
"todo-comments.nvim": { "branch": "main", "commit": "8f45f353dc3649cb9b44cecda96827ea88128584" },
|
||||
"tokyonight.nvim": { "branch": "main", "commit": "b0e7c7382a7e8f6456f2a95655983993ffda745e" },
|
||||
"trouble.nvim": { "branch": "main", "commit": "6efc446226679fda0547c0fd6a7892fd5f5b15d8" },
|
||||
|
||||
@@ -16,7 +16,7 @@ return {
|
||||
}, -- lua
|
||||
clangd = true, -- C/C++
|
||||
gradle_ls = true, -- java package manager
|
||||
jdtls = true, -- java eclipse lsp
|
||||
-- jdtls = true, -- java eclipse lsp
|
||||
kotlin_language_server = true, -- kotlin
|
||||
pyright = true, -- python
|
||||
rust_analyzer = false, -- NOTE: using rustaceanvim
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
-- NOTE: Not language servers but still make sure mason installs them
|
||||
local ensure_installed = {
|
||||
stylua = true, -- lua formatting
|
||||
jdtls = true, -- java eclipse lsp
|
||||
}
|
||||
local servers = require('custom.config.language-servers')
|
||||
|
||||
@@ -29,5 +30,12 @@ require('mason-lspconfig').setup({ ensure_installed = servers_to_install })
|
||||
require('mason-tool-installer').setup({
|
||||
ensure_installed = {
|
||||
'stylua', -- lua formatter
|
||||
'java-debug-adapter',
|
||||
'java-test',
|
||||
},
|
||||
})
|
||||
|
||||
-- NOTE: apparently needed due to some issue or smthing?
|
||||
vim.api.nvim_command('MasonToolsInstall')
|
||||
|
||||
|
||||
|
||||
154
.config/nvim/lua/custom/plugins/nvim-jdtls.lua
Normal file
154
.config/nvim/lua/custom/plugins/nvim-jdtls.lua
Normal file
@@ -0,0 +1,154 @@
|
||||
return {
|
||||
'mfussenegger/nvim-jdtls',
|
||||
ft = { 'java' },
|
||||
dependencies = { 'mfussenegger/nvim-dap', 'williamboman/mason-lspconfig.nvim' },
|
||||
opts = function(_, opts)
|
||||
local jdtls = require('jdtls')
|
||||
local root_markers = { '.git', 'mvnw', 'gradlew', 'pom.xml', 'build.gradle', '.project' }
|
||||
local root_dir = require('jdtls.setup').find_root(root_markers)
|
||||
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
|
||||
os.execute('mkdir ' .. workspace_dir)
|
||||
|
||||
local defaults = {
|
||||
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',
|
||||
-- WARNING: Might need to change to config_linux or smthing
|
||||
vim.fn.expand('$MASON/share/jdtls/config'),
|
||||
'-data',
|
||||
workspace_dir,
|
||||
},
|
||||
root_dir = root_dir,
|
||||
settings = {
|
||||
java = {
|
||||
-- WARNING: might need home = 'path'
|
||||
-- WARNING: might need configuration.runtimes = {} of paths
|
||||
eclipse = { downloadSources = true },
|
||||
configuration = { updateBuildConfiguration = 'interactive' },
|
||||
maven = { downloadSources = true },
|
||||
implementationsCodeLens = { enabled = true },
|
||||
referencesCodeLens = { enabled = true },
|
||||
-- NOTE: maybe want to uncomment this
|
||||
-- references = { includeDecompiledSources = true, },
|
||||
-- signatureHelp = { enabled = true },
|
||||
-- format = {
|
||||
-- enabled = true,
|
||||
-- -- Formatting works by default, but you can refer to a specific file/URL if you choose
|
||||
-- -- settings = {
|
||||
-- -- url = "https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml",
|
||||
-- -- profile = "GoogleStyle",
|
||||
-- -- },
|
||||
-- },
|
||||
},
|
||||
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.*',
|
||||
},
|
||||
-- importOrder = {
|
||||
-- 'java',
|
||||
-- 'javax',
|
||||
-- 'com',
|
||||
-- 'org',
|
||||
-- },
|
||||
},
|
||||
-- extendedClientCapabilities = jdtls.extendedClientCapabilities,
|
||||
sources = {
|
||||
organizeImports = {
|
||||
starThreshold = 9999,
|
||||
staticStarThreshold = 9999,
|
||||
},
|
||||
},
|
||||
-- codeGeneration = {
|
||||
-- toString = {
|
||||
-- template = '${object.className}{${member.name()}=${member.value}, ${otherMembers}}',
|
||||
-- },
|
||||
-- useBlocks = true,
|
||||
-- },
|
||||
},
|
||||
-- Needed for auto-completion with method signatures and placeholders
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
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', {})),
|
||||
},
|
||||
},
|
||||
-- flags = { allow_incremental_sync = true },
|
||||
handlers = {
|
||||
['$/progress'] = function()
|
||||
-- disable progress updates.
|
||||
end,
|
||||
},
|
||||
filetypes = { 'java' },
|
||||
on_attach = function(client, bufnr)
|
||||
jdtls.setup_dap({ hotcodereplace = 'auto' })
|
||||
end,
|
||||
}
|
||||
|
||||
-- ensure that table is valid
|
||||
if not opts then
|
||||
opts = {}
|
||||
end
|
||||
|
||||
-- extend the current table with the defaults keeping options in the user opts
|
||||
-- this allows users to pass opts through an opts table in community.lua
|
||||
opts = vim.tbl_deep_extend('keep', opts, defaults)
|
||||
|
||||
-- send opts to config
|
||||
return 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)
|
||||
-- require('jdtls.dap').setup_dap_main_class_configs()
|
||||
else
|
||||
-- require('astronvim.utils').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,
|
||||
}
|
||||
Reference in New Issue
Block a user