feat: add jdtls

This commit is contained in:
Fabio Lenherr 2023-02-23 23:09:14 +01:00
parent 76b5001e19
commit 01baf4e9fa
8 changed files with 256 additions and 35 deletions

View file

@ -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)

View file

@ -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" },

View file

@ -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,
},

View file

@ -0,0 +1,3 @@
local M = {}
return M

View file

@ -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

View file

@ -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",
},
},
},
},
}