feat: add jdtls
This commit is contained in:
parent
76b5001e19
commit
01baf4e9fa
8 changed files with 256 additions and 35 deletions
46
nvim/ftplugin/java.lua
Normal file
46
nvim/ftplugin/java.lua
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
local jdtls = require("jdtls")
|
||||
|
||||
jdtls.start_or_attach({
|
||||
cmd = { "jdtls" },
|
||||
root_dir = vim.fs.dirname(vim.fs.find({ "settings.gradle", ".git", "pom.xml" }, { upward = true })[1]),
|
||||
init_options = {
|
||||
bundles = vim.list_extend(
|
||||
{
|
||||
-- Mason: java-debug-adapter
|
||||
-- stylua: ignore
|
||||
vim.fn.glob( "~/.local/share/nvim/mason/packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar", 1),
|
||||
},
|
||||
-- Mason: java-test
|
||||
-- stylua: ignore
|
||||
vim.split(vim.fn.glob("~/.local/share/nvim/mason/packages/java-test/extension/server/*.jar", 1), "\n")
|
||||
),
|
||||
},
|
||||
on_attach = function()
|
||||
jdtls.setup_dap() -- Create new dap adapter for java
|
||||
|
||||
-- nvim-jdtls specific mappings
|
||||
vim.keymap.set("n", "<a-o>", jdtls.organize_imports, {})
|
||||
vim.keymap.set("n", "crv", jdtls.extract_variable, {})
|
||||
vim.keymap.set("v", "crv", jdtls.extract_variable, {})
|
||||
vim.keymap.set("n", "crc", jdtls.extract_constant, {})
|
||||
vim.keymap.set("v", "crc", jdtls.extract_constant, {})
|
||||
vim.keymap.set("v", "crm", jdtls.extract_method, {})
|
||||
|
||||
vim.keymap.set("n", "<leader>df", jdtls.test_class, {})
|
||||
vim.keymap.set("n", "<leader>dn", jdtls.test_nearest_method, {})
|
||||
end,
|
||||
})
|
||||
|
||||
local dap_status, dap = pcall(require, "dap")
|
||||
if not dap_status then
|
||||
return
|
||||
end
|
||||
|
||||
dap.configurations.java = {
|
||||
{
|
||||
name = "Launch current file",
|
||||
type = "java",
|
||||
request = "launch",
|
||||
program = "${file}",
|
||||
},
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"LazyVim": { "branch": "main", "commit": "befa6c67a4387b0db4f8421d463f5d03f91dc829" },
|
||||
"LuaSnip": { "branch": "master", "commit": "d33cf7de14eea209b8ed4a7edaed72f0b8cedb30" },
|
||||
"LuaSnip": { "branch": "master", "commit": "f7c845749aba6096f041a73a26ba64f3817bab99" },
|
||||
"alpha-nvim": { "branch": "main", "commit": "b6c7b5d9d6d2633722255abf2be3ecb8733e8d2d" },
|
||||
"bufferline.nvim": { "branch": "main", "commit": "cbb798dd2db7841550cd2c6c6dde12dfda055928" },
|
||||
"catppuccin": { "branch": "main", "commit": "4175759297350557315987d479fb687a9f0b781f" },
|
||||
|
|
@ -22,11 +22,11 @@
|
|||
"markdown-preview.nvim": { "branch": "master", "commit": "02cc3874738bc0f86e4b91f09b8a0ac88aef8e96" },
|
||||
"mason-lspconfig.nvim": { "branch": "main", "commit": "93e58e100f37ef4fb0f897deeed20599dae9d128" },
|
||||
"mason-nvim-dap.nvim": { "branch": "main", "commit": "6b5b5fc42176e0ca1d3634a516cc9b4e5fcc8117" },
|
||||
"mason.nvim": { "branch": "main", "commit": "11e34da70dc531e5d917fd4303db2d81258f6ada" },
|
||||
"mason.nvim": { "branch": "main", "commit": "01dfdfd36be77cb1195b60d580315bf4e2d8e62c" },
|
||||
"mini.ai": { "branch": "main", "commit": "d50b4d87e38d21ca2c5facee9f8a205ddb768358" },
|
||||
"mini.bufremove": { "branch": "main", "commit": "351d18d596f7eac4589b67b4b87ed1708c545dd3" },
|
||||
"mini.comment": { "branch": "main", "commit": "9fc3fe43129e8c2611bd21b8f50af8c0d0742533" },
|
||||
"mini.indentscope": { "branch": "main", "commit": "d3e907b13298b0fc60db289fb804be7e9c561922" },
|
||||
"mini.comment": { "branch": "main", "commit": "922e191c76c261e03ddbe62787e037e9b5aef97f" },
|
||||
"mini.indentscope": { "branch": "main", "commit": "d8938d056c5d4154fd7faef5cf0b0e86ea587a27" },
|
||||
"mini.pairs": { "branch": "main", "commit": "4ebc1ff8d77fe75e8f219432302800ca29e17614" },
|
||||
"mini.surround": { "branch": "main", "commit": "6a4f31e2a380439315729f561d7e7898bde1fd52" },
|
||||
"neo-tree.nvim": { "branch": "v2.x", "commit": "74040b34278910d9b467fd914862e2a9a1ebacaa" },
|
||||
|
|
@ -39,12 +39,14 @@
|
|||
"nvim-dap": { "branch": "master", "commit": "fd291e970aa7c46ba2c49448f7d2c94cc7828f4e" },
|
||||
"nvim-dap-ui": { "branch": "master", "commit": "bdb94e3853d11b5ce98ec182e5a3719d5c0ef6fd" },
|
||||
"nvim-dap-virtual-text": { "branch": "master", "commit": "8db23ea51203b5f00ad107a0cef7e0b2d7a0476c" },
|
||||
"nvim-dap-vscode-js": { "branch": "main", "commit": "e7c05495934a658c8aa10afd995dacd796f76091" },
|
||||
"nvim-highlight-colors": { "branch": "main", "commit": "af051bfe2971fc888d21cdfc59f5444904353b43" },
|
||||
"nvim-jdtls": { "branch": "master", "commit": "8fe3be1c08ab0bb55f2998fbc02f1a08f87a44bc" },
|
||||
"nvim-lspconfig": { "branch": "master", "commit": "69e2fe3d638566a812c39bc4ea1980f7b833e2fc" },
|
||||
"nvim-navic": { "branch": "master", "commit": "7e9d2b2b601149fecdccd11b516acb721e571fe6" },
|
||||
"nvim-notify": { "branch": "master", "commit": "9c987081390753b625e2d94e749e80e9b4a3e082" },
|
||||
"nvim-spectre": { "branch": "master", "commit": "ce73d505fdc45f16c1a04f6a98c1c1e114841708" },
|
||||
"nvim-treesitter": { "branch": "master", "commit": "454876fc6d25a699178cb66aeda4014dedb765f3" },
|
||||
"nvim-treesitter": { "branch": "master", "commit": "83e2e22d9e25d739093c38f0663d547dfea00cf4" },
|
||||
"nvim-treesitter-textobjects": { "branch": "master", "commit": "2f3583001e2bf793480f38cf0d055571787b0259" },
|
||||
"nvim-ts-context-commentstring": { "branch": "main", "commit": "a0f89563ba36b3bacd62cf967b46beb4c2c29e52" },
|
||||
"nvim-web-devicons": { "branch": "master", "commit": "4709a504d2cd2680fb511675e64ef2790d491d36" },
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ map("n", "f", ":Neotree action=focus toggle=true<CR>", opts)
|
|||
map("n", "<C-d>", ":lua require('toggleterm').toggle(1)<CR>", opts)
|
||||
|
||||
-- tab switching
|
||||
map("n", "<F1>", ":BufferPrev<CR>", opts)
|
||||
map("n", "<F2>", ":BufferNext<CR>", opts)
|
||||
map("n", "<F1>", ":BufferLineCyclePrev<CR>", opts)
|
||||
map("n", "<F2>", ":BufferLineCycleNext<CR>", opts)
|
||||
|
||||
-- formatting
|
||||
map("n", "<F4>", ":lua vim.lsp.buf.format { async = true }<CR>", opts)
|
||||
|
|
|
|||
|
|
@ -23,14 +23,29 @@ return {
|
|||
require("luasnip.loaders.from_lua").load({ paths = "~/.config/nvim/snippets" })
|
||||
end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<Tab>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
|
||||
["<S-Tab>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
|
||||
mapping = {
|
||||
["<C-b>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-Space>"] = cmp.mapping.complete(),
|
||||
["<C-e>"] = cmp.mapping.abort(),
|
||||
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
||||
["<CR>"] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
||||
["<Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, {
|
||||
"i",
|
||||
"s",
|
||||
}),
|
||||
["<C-j>"] = cmp.mapping(function(fallback)
|
||||
if luasnip.expandable() then
|
||||
luasnip.expand()
|
||||
|
|
@ -53,7 +68,7 @@ return {
|
|||
"i",
|
||||
"s",
|
||||
}),
|
||||
}),
|
||||
},
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
|
|
|
|||
|
|
@ -1,11 +1,37 @@
|
|||
return {
|
||||
{
|
||||
"mxsdev/nvim-dap-vscode-js",
|
||||
build = "npm install --legacy-peer-deps && npm run compile",
|
||||
},
|
||||
{
|
||||
"mfussenegger/nvim-dap",
|
||||
lazy = true,
|
||||
dependencies = {
|
||||
"rcarriga/nvim-dap-ui",
|
||||
"theHamsta/nvim-dap-virtual-text",
|
||||
"jayp0521/mason-nvim-dap.nvim",
|
||||
{
|
||||
"jay-babu/mason-nvim-dap.nvim",
|
||||
opts = {
|
||||
ensure_installed = {
|
||||
"node2",
|
||||
"python",
|
||||
"javadbg",
|
||||
"javatest",
|
||||
"codelldb",
|
||||
"firefox",
|
||||
"bash",
|
||||
"delve",
|
||||
},
|
||||
automatic_installation = true,
|
||||
automatic_setup = true,
|
||||
},
|
||||
config = function(_, opts)
|
||||
require("mason-nvim-dap").setup(opts)
|
||||
require("mason-nvim-dap").setup_handlers({
|
||||
javadbg = function() end,
|
||||
})
|
||||
end,
|
||||
},
|
||||
},
|
||||
config = function()
|
||||
local dap = require("dap")
|
||||
|
|
@ -50,6 +76,86 @@ return {
|
|||
}
|
||||
dap.configurations.c = dap.configurations.cpp
|
||||
|
||||
dap.configurations.python = {
|
||||
{
|
||||
-- The first three options are required by nvim-dap
|
||||
type = "python", -- the type here established the link to the adapter definition: `dap.adapters.python`
|
||||
request = "launch",
|
||||
name = "Launch file",
|
||||
|
||||
-- Options below are for debugpy, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for supported options
|
||||
|
||||
program = "${file}", -- This configuration will launch the current file if used.
|
||||
pythonPath = function()
|
||||
-- debugpy supports launching an application with a different interpreter then the one used to launch debugpy itself.
|
||||
-- The code below looks for a `venv` or `.venv` folder in the current directly and uses the python within.
|
||||
-- You could adapt this - to for example use the `VIRTUAL_ENV` environment variable.
|
||||
local cwd = vim.fn.getcwd()
|
||||
if vim.fn.executable(cwd .. "/venv/bin/python") == 1 then
|
||||
return cwd .. "/venv/bin/python"
|
||||
elseif vim.fn.executable(cwd .. "/.venv/bin/python") == 1 then
|
||||
return cwd .. "/.venv/bin/python"
|
||||
else
|
||||
return "/usr/bin/python"
|
||||
end
|
||||
end,
|
||||
},
|
||||
}
|
||||
dap.configurations.java = {
|
||||
{
|
||||
-- type = "javadbg",
|
||||
request = "attach",
|
||||
name = "Debug (Attach) - Remote",
|
||||
hostName = "127.0.0.1",
|
||||
port = 5005,
|
||||
},
|
||||
}
|
||||
dap.configurations.go = {
|
||||
{
|
||||
type = "delve",
|
||||
name = "Debug",
|
||||
request = "launch",
|
||||
program = "${file}",
|
||||
},
|
||||
{
|
||||
type = "delve",
|
||||
name = "Debug test", -- configuration for debugging test files
|
||||
request = "launch",
|
||||
mode = "test",
|
||||
program = "${file}",
|
||||
},
|
||||
-- works with go.mod packages and sub packages
|
||||
{
|
||||
type = "delve",
|
||||
name = "Debug test (go.mod)",
|
||||
request = "launch",
|
||||
mode = "test",
|
||||
program = "./${relativeFileDirname}",
|
||||
},
|
||||
}
|
||||
dap.configurations.javascript = {
|
||||
{
|
||||
name = "Launch",
|
||||
type = "js",
|
||||
request = "launch",
|
||||
program = "${file}",
|
||||
cwd = vim.fn.getcwd(),
|
||||
sourceMaps = true,
|
||||
protocol = "inspector",
|
||||
console = "integratedTerminal",
|
||||
},
|
||||
}
|
||||
dap.configurations.typescript = {
|
||||
{
|
||||
name = "Debug with Firefox",
|
||||
type = "firefox",
|
||||
request = "launch",
|
||||
reAttach = true,
|
||||
url = "http://localhost:3000",
|
||||
webRoot = "${workspaceFolder}",
|
||||
firefoxExecutable = "/usr/bin/firefox",
|
||||
},
|
||||
}
|
||||
require("dapui").setup({
|
||||
icons = { expanded = "▾", collapsed = "▸", current_frame = "▸" },
|
||||
mappings = {
|
||||
|
|
@ -123,15 +229,59 @@ return {
|
|||
},
|
||||
})
|
||||
|
||||
require("mason-nvim-dap").setup({
|
||||
ensure_installed = {
|
||||
"bash-debug-adapter",
|
||||
"firefox-debug-adapter",
|
||||
"js-debug-adapter",
|
||||
"node-debug2-adapter",
|
||||
},
|
||||
})
|
||||
-- require("mason-nvim-dap").setup({
|
||||
-- ensure_installed = {
|
||||
-- "bash-debug-adapter",
|
||||
-- "firefox-debug-adapter",
|
||||
-- "js-debug-adapter",
|
||||
-- "node-debug2-adapter",
|
||||
-- "java-debug-adapter",
|
||||
-- "debugpy",
|
||||
-- },
|
||||
-- automatic_installation = true,
|
||||
-- automatic_setup = true,
|
||||
-- })
|
||||
-- require("mason-nvim-dap").setup_handlers({
|
||||
-- function(source_name)
|
||||
-- -- all sources with no handler get passed here
|
||||
--
|
||||
-- -- Keep original functionality of `automatic_setup = true`
|
||||
-- require("mason-nvim-dap.automatic_setup")(source_name)
|
||||
-- end,
|
||||
-- python = function(source_name)
|
||||
-- dap.adapters.python = {
|
||||
-- type = "executable",
|
||||
-- command = "/usr/bin/python3",
|
||||
-- args = {
|
||||
-- "-m",
|
||||
-- "debugpy.adapter",
|
||||
-- },
|
||||
-- }
|
||||
--
|
||||
-- dap.configurations.python = {
|
||||
-- {
|
||||
-- type = "python",
|
||||
-- request = "launch",
|
||||
-- name = "Launch file",
|
||||
-- program = "${file}", -- This configuration will launch the current file if used.
|
||||
-- },
|
||||
-- }
|
||||
-- end,
|
||||
-- })
|
||||
local dap = require("dap")
|
||||
dap.configurations.lua = {
|
||||
|
||||
{
|
||||
|
||||
type = "nlua",
|
||||
request = "attach",
|
||||
name = "Attach to running Neovim instance",
|
||||
},
|
||||
}
|
||||
|
||||
dap.adapters.nlua = function(callback, config)
|
||||
callback({ type = "server", host = config.host or "127.0.0.1", port = config.port or 8086 })
|
||||
end
|
||||
require("nvim-dap-virtual-text").setup()
|
||||
end,
|
||||
},
|
||||
|
|
|
|||
3
nvim/lua/plugins/java.lua
Normal file
3
nvim/lua/plugins/java.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
local M = {}
|
||||
|
||||
return M
|
||||
|
|
@ -9,6 +9,7 @@ return {
|
|||
"mason.nvim",
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
"lvimuser/lsp-inlayhints.nvim",
|
||||
"mfussenegger/nvim-jdtls",
|
||||
{
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
cond = function()
|
||||
|
|
@ -75,7 +76,7 @@ return {
|
|||
},
|
||||
},
|
||||
-- ltex = {},
|
||||
jdtls = {},
|
||||
ltex = {},
|
||||
gopls = {},
|
||||
sqls = {},
|
||||
taplo = {},
|
||||
|
|
@ -95,20 +96,12 @@ return {
|
|||
},
|
||||
},
|
||||
},
|
||||
-- you can do any additional lsp server setup here
|
||||
-- return true if you don't want this server to be setup with lspconfig
|
||||
---@type table<string, fun(server:string, opts:_.lspconfig.options):boolean?>
|
||||
setup = {
|
||||
-- example to setup with typescript.nvim
|
||||
-- tsserver = function(_, opts)
|
||||
-- require("typescript").setup({ server = opts })
|
||||
-- return true
|
||||
-- end,
|
||||
-- Specify * to use this function as a fallback for any server
|
||||
-- ["*"] = function(server, opts) end,
|
||||
jdtls = function()
|
||||
return true
|
||||
end,
|
||||
},
|
||||
},
|
||||
---@param opts PluginLspOpts
|
||||
config = function(plugin, opts)
|
||||
-- setup autoformat
|
||||
require("lazyvim.plugins.lsp.format").autoformat = opts.autoformat
|
||||
|
|
|
|||
|
|
@ -93,8 +93,6 @@ return {
|
|||
},
|
||||
{
|
||||
"lervag/vimtex",
|
||||
lazy = true,
|
||||
event = "FileType tex",
|
||||
config = function()
|
||||
-- require("vimtex").setup()
|
||||
vim.cmd("let g:vimtex_quickfix_mode=0")
|
||||
|
|
@ -105,4 +103,18 @@ return {
|
|||
)
|
||||
end,
|
||||
},
|
||||
{
|
||||
"nvim-neo-tree/neo-tree.nvim",
|
||||
opts = {
|
||||
close_if_last_window = true,
|
||||
filesystem = {
|
||||
group_empty_dirs = true,
|
||||
},
|
||||
window = {
|
||||
mappings = {
|
||||
["f"] = "close_window",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue