return { -- lsp configuration "neovim/nvim-lspconfig", event = { "BufReadPre", "BufNewFile" }, dependencies = { "hrsh7th/cmp-nvim-lsp", { "antosha417/nvim-lsp-file-operations", config = true }, -- "mfussenegger/nvim-jdtls", "nvim-java/nvim-java" }, 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 -- Change the Diagnostic symbols in the sign column (gutter) local signs = { Error = "󰅚 ", Warn = "󰀪 ", Hint = "󰌶", Info = "󰋽 " } for type, icon in pairs(signs) do local hl = "DiagnosticSign" .. type vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) end lspconfig.bashls.setup({ capabilities = capabilities, on_attach = on_attach, }) lspconfig.clangd.setup({ cmd = { "clangd", "--suggest-missing-includes", "--clang-tidy", }, filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto", "ino" }, capabilities = capabilities, on_attach = on_attach, }) lspconfig.cssls.setup({ capabilities = capabilities, on_attach = on_attach, }) lspconfig.html.setup({ capabilities = capabilities, on_attach = on_attach, }) lspconfig.lua_ls.setup({ capabilities = capabilities, on_attach = on_attach, settings = { Lua = { -- make the language server recognize "vim" global diagnostics = { globals = { "vim" }, }, workspace = { -- make language server aware of runtime files library = { [vim.fn.expand("$VIMRUNTIME/lua")] = true, [vim.fn.stdpath("config") .. "/lua"] = true, }, }, }, }, }) lspconfig.pyright.setup({ capabilities = capabilities, on_attach = on_attach, }) 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, }) lspconfig.texlab.setup{ cmd = { "texlab" }, filetypes = { "tex", "latex", "bib" }, root_dir = function(fname) return vim.loop.cwd() end, } end, }