190 lines
6.8 KiB
Lua
Executable File
190 lines
6.8 KiB
Lua
Executable File
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", "<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
|
|
|
|
-- 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", "<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,
|
|
})
|
|
|
|
lspconfig.texlab.setup{
|
|
cmd = { "texlab" },
|
|
filetypes = { "tex", "latex", "bib" },
|
|
root_dir = function(fname)
|
|
return vim.loop.cwd()
|
|
end,
|
|
}
|
|
|
|
end,
|
|
}
|