[LSP] Java setup rework
This commit is contained in:
parent
641511b845
commit
37bf15d060
@ -5,74 +5,17 @@ return {
|
||||
dependencies = {
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
{ "antosha417/nvim-lsp-file-operations", config = true },
|
||||
-- "mfussenegger/nvim-jdtls",
|
||||
"nvim-java/nvim-java",
|
||||
"mfussenegger/nvim-jdtls",
|
||||
},
|
||||
config = function()
|
||||
require("java").setup()
|
||||
-- import lspconfig plugin
|
||||
local lspconfig = require("lspconfig")
|
||||
|
||||
-- import cmp-nvim-lsp plugin
|
||||
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
||||
|
||||
local keymap = vim.keymap
|
||||
|
||||
local opts = { silent = true }
|
||||
|
||||
local on_attach = function(client, bufnr)
|
||||
opts.buffer = bufnr
|
||||
|
||||
-- set keybinds
|
||||
opts.desc = "Show LSP references"
|
||||
keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts)
|
||||
|
||||
opts.desc = "Go to declaration"
|
||||
keymap.set("n", "gD", ":lua vim.lsp.buf.declaration", opts)
|
||||
|
||||
opts.desc = "Show LSP definitions"
|
||||
keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
|
||||
|
||||
opts.desc = "Show LSP implementations"
|
||||
keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts)
|
||||
|
||||
opts.desc = "Show LSP type definitions"
|
||||
keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts)
|
||||
|
||||
opts.desc = "See available code actions"
|
||||
keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts)
|
||||
|
||||
opts.desc = "Format current file"
|
||||
keymap.set("n", "<leader>gf", vim.lsp.buf.format, opts)
|
||||
|
||||
opts.desc = "Smart rename"
|
||||
keymap.set("n", "<leader>n", vim.lsp.buf.rename, opts)
|
||||
|
||||
opts.desc = "Show buffer diagnostics"
|
||||
keymap.set("n", "ga", "<cmd>Telescope diagnostics bufnr=0<CR>", opts)
|
||||
|
||||
opts.desc = "Show line diagnostics"
|
||||
keymap.set("n", "gA", ":lua vim.diagnostic.open_float()<CR>", opts)
|
||||
|
||||
opts.desc = "Go to previous diagnostic"
|
||||
keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
|
||||
|
||||
opts.desc = "Go to next diagnostic"
|
||||
keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
|
||||
|
||||
opts.desc = "Show documentation for what is under cursor"
|
||||
keymap.set("n", "<leader>k", vim.lsp.buf.hover, opts)
|
||||
|
||||
opts.desc = "Restart LSP"
|
||||
keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts)
|
||||
|
||||
vim.opt.signcolumn = "yes" -- reserve space for diagnostics
|
||||
end
|
||||
|
||||
-- used to enable autocompletion (assign to every lsp server config)
|
||||
-- local capabilities = cmp_nvim_lsp.default_capabilities()
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
local capabilities = require('lsp-options').capabilities
|
||||
local on_attach = require('lsp-options').on_attach
|
||||
|
||||
-- Change the Diagnostic symbols in the sign column (gutter)
|
||||
local signs = { Error = " ", Warn = " ", Hint = "", Info = " " }
|
||||
@ -179,56 +122,17 @@ return {
|
||||
},
|
||||
})
|
||||
|
||||
-- ┌ ┐
|
||||
-- │ ASM │
|
||||
-- └ ┘
|
||||
lspconfig.asm_lsp.setup({
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
})
|
||||
|
||||
local java_on_attach = function(client, bufnr)
|
||||
on_attach(client, bufnr)
|
||||
|
||||
opts.buffer = bufnr
|
||||
-- Keybinds for testing, refactoring, java specific
|
||||
opts.desc = "Java profiling"
|
||||
keymap.set("n", "<leader>jp", ":JavaProfile<CR>", opts)
|
||||
|
||||
opts.desc = "Java Refactor: Extract Variable (create variable from cursor)"
|
||||
keymap.set("n", "<leader>jev", ":JavaExtractVariable<CR>", opts)
|
||||
|
||||
opts.desc = "Java Refactor: Extract Variable all occurrences (create variable from cursor)"
|
||||
keymap.set("n", "<leader>jea", ":JavaExtractVariableAllOccurrence<CR>", opts)
|
||||
|
||||
opts.desc = "Java Refactor: Extract Const (create const from cursor)"
|
||||
keymap.set("n", "<leader>jec", ":JavaExtractConst<CR>", opts)
|
||||
|
||||
opts.desc = "Java Refactor: Extract Method (create method from cursor)"
|
||||
keymap.set("n", "<leader>jev", ":JavaExtractMethod<CR>", opts)
|
||||
|
||||
opts.desc = "Java Refactor: Extract Field (create field from cursor)"
|
||||
keymap.set("n", "<leader>jev", ":JavaExtractField<CR>", opts)
|
||||
|
||||
-- Java testing, Debugging
|
||||
opts.desc = "Java Testing: Run test class in buffer"
|
||||
keymap.set("n", "<leader>jtc", ":JavaTestRunCurrentClass<CR>", opts)
|
||||
|
||||
opts.desc = "Java Testing: Debug test class in buffer"
|
||||
keymap.set("n", "<leader>jdc", ":JavaTestDebugCurrentClass<CR>", opts)
|
||||
|
||||
opts.desc = "Java Testing: Run current method in buffer"
|
||||
keymap.set("n", "<leader>jtm", ":JavaTestRunCurrentMethod<CR>", opts)
|
||||
|
||||
opts.desc = "Java Testing: Debug current method in buffer"
|
||||
keymap.set("n", "<leader>jdm", ":JavaTestDebugCurrentMethod<CR>", opts)
|
||||
|
||||
opts.desc = "Java Testing: View last report"
|
||||
keymap.set("n", "<leader>jtv", ":JavaTestViewLastReport<CR>", opts)
|
||||
end
|
||||
|
||||
lspconfig.jdtls.setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = java_on_attach,
|
||||
})
|
||||
|
||||
-- ┌ ┐
|
||||
-- │ LaTeX │
|
||||
-- └ ┘
|
||||
lspconfig.texlab.setup({
|
||||
cmd = { "texlab" },
|
||||
filetypes = { "tex", "latex", "bib" },
|
||||
@ -237,6 +141,9 @@ return {
|
||||
end,
|
||||
})
|
||||
|
||||
-- ┌ ┐
|
||||
-- │ Verilog │
|
||||
-- └ ┘
|
||||
local lspconfutil = require("lspconfig/util")
|
||||
local root_pattern = lspconfutil.root_pattern("veridian.yml", ".git", ".xpr")
|
||||
local verilog_root_dir = function()
|
||||
|
@ -35,7 +35,7 @@ return {
|
||||
"volar"
|
||||
},
|
||||
-- auto-install configured servers (with lspconfig)
|
||||
automatic_installation = true,
|
||||
automatic_installation = false,
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user