From 37bf15d060a2e200de1d131617172f03c0e6ebe5 Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Thu, 15 May 2025 15:16:00 +0200 Subject: [PATCH] [LSP] Java setup rework --- nvim/lua/plugins/lsp/lspconfig.lua | 117 +++-------------------------- nvim/lua/plugins/lsp/mason.lua | 2 +- 2 files changed, 13 insertions(+), 106 deletions(-) diff --git a/nvim/lua/plugins/lsp/lspconfig.lua b/nvim/lua/plugins/lsp/lspconfig.lua index cb828ff..7d612db 100755 --- a/nvim/lua/plugins/lsp/lspconfig.lua +++ b/nvim/lua/plugins/lsp/lspconfig.lua @@ -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", "Telescope lsp_references", 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", "Telescope lsp_definitions", opts) - - opts.desc = "Show LSP implementations" - keymap.set("n", "gi", "Telescope lsp_implementations", opts) - - opts.desc = "Show LSP type definitions" - keymap.set("n", "gt", "Telescope lsp_type_definitions", opts) - - opts.desc = "See available code actions" - keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, opts) - - opts.desc = "Format current file" - keymap.set("n", "gf", vim.lsp.buf.format, opts) - - opts.desc = "Smart rename" - keymap.set("n", "n", vim.lsp.buf.rename, opts) - - opts.desc = "Show buffer diagnostics" - keymap.set("n", "ga", "Telescope diagnostics bufnr=0", opts) - - opts.desc = "Show line diagnostics" - keymap.set("n", "gA", ":lua vim.diagnostic.open_float()", 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", "k", vim.lsp.buf.hover, opts) - - opts.desc = "Restart LSP" - keymap.set("n", "rs", ":LspRestart", 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", "jp", ":JavaProfile", opts) - - opts.desc = "Java Refactor: Extract Variable (create variable from cursor)" - keymap.set("n", "jev", ":JavaExtractVariable", opts) - - opts.desc = "Java Refactor: Extract Variable all occurrences (create variable from cursor)" - keymap.set("n", "jea", ":JavaExtractVariableAllOccurrence", opts) - - opts.desc = "Java Refactor: Extract Const (create const from cursor)" - keymap.set("n", "jec", ":JavaExtractConst", opts) - - opts.desc = "Java Refactor: Extract Method (create method from cursor)" - keymap.set("n", "jev", ":JavaExtractMethod", opts) - - opts.desc = "Java Refactor: Extract Field (create field from cursor)" - keymap.set("n", "jev", ":JavaExtractField", opts) - - -- Java testing, Debugging - opts.desc = "Java Testing: Run test class in buffer" - keymap.set("n", "jtc", ":JavaTestRunCurrentClass", opts) - - opts.desc = "Java Testing: Debug test class in buffer" - keymap.set("n", "jdc", ":JavaTestDebugCurrentClass", opts) - - opts.desc = "Java Testing: Run current method in buffer" - keymap.set("n", "jtm", ":JavaTestRunCurrentMethod", opts) - - opts.desc = "Java Testing: Debug current method in buffer" - keymap.set("n", "jdm", ":JavaTestDebugCurrentMethod", opts) - - opts.desc = "Java Testing: View last report" - keymap.set("n", "jtv", ":JavaTestViewLastReport", 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() diff --git a/nvim/lua/plugins/lsp/mason.lua b/nvim/lua/plugins/lsp/mason.lua index 222123d..10a67a4 100755 --- a/nvim/lua/plugins/lsp/mason.lua +++ b/nvim/lua/plugins/lsp/mason.lua @@ -35,7 +35,7 @@ return { "volar" }, -- auto-install configured servers (with lspconfig) - automatic_installation = true, + automatic_installation = false, }) end, }