[LSP] Format, add asm lsp

This commit is contained in:
Admin 2025-05-02 07:49:33 +02:00
parent 67363070e3
commit f7d3c8b24b

View File

@ -1,255 +1,260 @@
return { return {
-- lsp configuration -- lsp configuration
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" }, event = { "BufReadPre", "BufNewFile" },
dependencies = { dependencies = {
"hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-nvim-lsp",
{ "antosha417/nvim-lsp-file-operations", config = true }, { "antosha417/nvim-lsp-file-operations", config = true },
-- "mfussenegger/nvim-jdtls", -- "mfussenegger/nvim-jdtls",
"nvim-java/nvim-java", "nvim-java/nvim-java",
}, },
config = function() config = function()
require("java").setup() require("java").setup()
-- import lspconfig plugin -- import lspconfig plugin
local lspconfig = require("lspconfig") local lspconfig = require("lspconfig")
-- import cmp-nvim-lsp plugin -- import cmp-nvim-lsp plugin
local cmp_nvim_lsp = require("cmp_nvim_lsp") local cmp_nvim_lsp = require("cmp_nvim_lsp")
local keymap = vim.keymap local keymap = vim.keymap
local opts = { silent = true } local opts = { silent = true }
local on_attach = function(client, bufnr) local on_attach = function(client, bufnr)
opts.buffer = bufnr opts.buffer = bufnr
-- set keybinds -- set keybinds
opts.desc = "Show LSP references" opts.desc = "Show LSP references"
keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts) keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts)
opts.desc = "Go to declaration" opts.desc = "Go to declaration"
keymap.set("n", "gD", ":lua vim.lsp.buf.declaration", opts) keymap.set("n", "gD", ":lua vim.lsp.buf.declaration", opts)
opts.desc = "Show LSP definitions" opts.desc = "Show LSP definitions"
keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts) keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
opts.desc = "Show LSP implementations" opts.desc = "Show LSP implementations"
keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts) keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts)
opts.desc = "Show LSP type definitions" opts.desc = "Show LSP type definitions"
keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts) keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts)
opts.desc = "See available code actions" opts.desc = "See available code actions"
keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts) keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts)
opts.desc = "Format current file" opts.desc = "Format current file"
keymap.set("n", "<leader>gf", vim.lsp.buf.format, opts) keymap.set("n", "<leader>gf", vim.lsp.buf.format, opts)
opts.desc = "Smart rename" opts.desc = "Smart rename"
keymap.set("n", "<leader>n", vim.lsp.buf.rename, opts) keymap.set("n", "<leader>n", vim.lsp.buf.rename, opts)
opts.desc = "Show buffer diagnostics" opts.desc = "Show buffer diagnostics"
keymap.set("n", "ga", "<cmd>Telescope diagnostics bufnr=0<CR>", opts) keymap.set("n", "ga", "<cmd>Telescope diagnostics bufnr=0<CR>", opts)
opts.desc = "Show line diagnostics" opts.desc = "Show line diagnostics"
keymap.set("n", "gA", ":lua vim.diagnostic.open_float()<CR>", opts) keymap.set("n", "gA", ":lua vim.diagnostic.open_float()<CR>", opts)
opts.desc = "Go to previous diagnostic" opts.desc = "Go to previous diagnostic"
keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
opts.desc = "Go to next diagnostic" opts.desc = "Go to next diagnostic"
keymap.set("n", "]d", vim.diagnostic.goto_next, opts) keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
opts.desc = "Show documentation for what is under cursor" opts.desc = "Show documentation for what is under cursor"
keymap.set("n", "<leader>k", vim.lsp.buf.hover, opts) keymap.set("n", "<leader>k", vim.lsp.buf.hover, opts)
opts.desc = "Restart LSP" opts.desc = "Restart LSP"
keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts) keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts)
vim.opt.signcolumn = "yes" -- reserve space for diagnostics vim.opt.signcolumn = "yes" -- reserve space for diagnostics
end end
-- used to enable autocompletion (assign to every lsp server config) -- used to enable autocompletion (assign to every lsp server config)
-- local capabilities = cmp_nvim_lsp.default_capabilities() -- local capabilities = cmp_nvim_lsp.default_capabilities()
local capabilities = vim.lsp.protocol.make_client_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true capabilities.textDocument.completion.completionItem.snippetSupport = true
-- Change the Diagnostic symbols in the sign column (gutter) -- Change the Diagnostic symbols in the sign column (gutter)
local signs = { Error = "󰅚 ", Warn = "󰀪 ", Hint = "󰌶", Info = "󰋽 " } local signs = { Error = "󰅚 ", Warn = "󰀪 ", Hint = "󰌶", Info = "󰋽 " }
for type, icon in pairs(signs) do for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end end
lspconfig.bashls.setup({ lspconfig.bashls.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
}) })
lspconfig.clangd.setup({ lspconfig.clangd.setup({
cmd = { cmd = {
"clangd", "clangd",
"--suggest-missing-includes", "--suggest-missing-includes",
"--clang-tidy", "--clang-tidy",
}, },
filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto", "ino" }, filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto", "ino" },
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
}) })
lspconfig.cssls.setup({ lspconfig.cssls.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
}) })
lspconfig.html.setup({ lspconfig.html.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
}) })
lspconfig.jsonls.setup({ lspconfig.jsonls.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
}) })
-- ┌ ┐ -- ┌ ┐
-- │ LUA │ -- │ LUA │
-- └ ┘ -- └ ┘
lspconfig.lua_ls.setup({ lspconfig.lua_ls.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
settings = { settings = {
Lua = { Lua = {
-- make the language server recognize "vim" global -- make the language server recognize "vim" global
diagnostics = { diagnostics = {
globals = { "vim" }, globals = { "vim" },
}, },
workspace = { workspace = {
-- make language server aware of runtime files -- make language server aware of runtime files
library = { library = {
[vim.fn.expand("$VIMRUNTIME/lua")] = true, [vim.fn.expand("$VIMRUNTIME/lua")] = true,
[vim.fn.stdpath("config") .. "/lua"] = true, [vim.fn.stdpath("config") .. "/lua"] = true,
}, },
}, },
}, },
}, },
}) })
lspconfig.marksman.setup({ lspconfig.marksman.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
}) })
-- ┌ ┐ -- ┌ ┐
-- │ Python │ -- │ Python │
-- └ ┘ -- └ ┘
lspconfig.pyright.setup({ lspconfig.pyright.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
}) })
-- ┌ ┐ -- ┌ ┐
-- │ Vue, TS, JS, TSX & JSX │ -- │ Vue, TS, JS, TSX & JSX │
-- └ ┘ -- └ ┘
lspconfig.volar.setup({ lspconfig.volar.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
}) })
local mason_packages = vim.fn.stdpath("data") .. "/mason/packages" local mason_packages = vim.fn.stdpath("data") .. "/mason/packages"
local volar_path = mason_packages .. "/vue-language-server/node_modules/@vue/language-server" local volar_path = mason_packages .. "/vue-language-server/node_modules/@vue/language-server"
lspconfig.ts_ls.setup({ lspconfig.ts_ls.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
init_options = { init_options = {
plugins = { plugins = {
{ {
name = "@vue/typescript-plugin", name = "@vue/typescript-plugin",
-- location = "/usr/lib/node_modules/@vue/typescript-plugin", -- location = "/usr/lib/node_modules/@vue/typescript-plugin",
location = volar_path, location = volar_path,
languages = { "vue" }, languages = { "vue" },
}, },
}, },
}, },
filetypes = { filetypes = {
"javascript", "javascript",
"typescript", "typescript",
"typescriptreact", "typescriptreact",
"javascriptreact", "javascriptreact",
"vue", "vue",
}, },
}) })
local java_on_attach = function(client, bufnr) lspconfig.asm_lsp.setup({
on_attach(client, bufnr) on_attach = on_attach,
capabilities = capabilities,
})
opts.buffer = bufnr local java_on_attach = function(client, bufnr)
-- Keybinds for testing, refactoring, java specific on_attach(client, bufnr)
opts.desc = "Java profiling"
keymap.set("n", "<leader>jp", ":JavaProfile<CR>", opts)
opts.desc = "Java Refactor: Extract Variable (create variable from cursor)" opts.buffer = bufnr
keymap.set("n", "<leader>jev", ":JavaExtractVariable<CR>", opts) -- Keybinds for testing, refactoring, java specific
opts.desc = "Java profiling"
keymap.set("n", "<leader>jp", ":JavaProfile<CR>", opts)
opts.desc = "Java Refactor: Extract Variable all occurrences (create variable from cursor)" opts.desc = "Java Refactor: Extract Variable (create variable from cursor)"
keymap.set("n", "<leader>jea", ":JavaExtractVariableAllOccurrence<CR>", opts) keymap.set("n", "<leader>jev", ":JavaExtractVariable<CR>", opts)
opts.desc = "Java Refactor: Extract Const (create const from cursor)" opts.desc = "Java Refactor: Extract Variable all occurrences (create variable from cursor)"
keymap.set("n", "<leader>jec", ":JavaExtractConst<CR>", opts) keymap.set("n", "<leader>jea", ":JavaExtractVariableAllOccurrence<CR>", opts)
opts.desc = "Java Refactor: Extract Method (create method from cursor)" opts.desc = "Java Refactor: Extract Const (create const from cursor)"
keymap.set("n", "<leader>jev", ":JavaExtractMethod<CR>", opts) keymap.set("n", "<leader>jec", ":JavaExtractConst<CR>", opts)
opts.desc = "Java Refactor: Extract Field (create field from cursor)" opts.desc = "Java Refactor: Extract Method (create method from cursor)"
keymap.set("n", "<leader>jev", ":JavaExtractField<CR>", opts) keymap.set("n", "<leader>jev", ":JavaExtractMethod<CR>", opts)
-- Java testing, Debugging opts.desc = "Java Refactor: Extract Field (create field from cursor)"
opts.desc = "Java Testing: Run test class in buffer" keymap.set("n", "<leader>jev", ":JavaExtractField<CR>", opts)
keymap.set("n", "<leader>jtc", ":JavaTestRunCurrentClass<CR>", opts)
opts.desc = "Java Testing: Debug test class in buffer" -- Java testing, Debugging
keymap.set("n", "<leader>jdc", ":JavaTestDebugCurrentClass<CR>", opts) opts.desc = "Java Testing: Run test class in buffer"
keymap.set("n", "<leader>jtc", ":JavaTestRunCurrentClass<CR>", opts)
opts.desc = "Java Testing: Run current method in buffer" opts.desc = "Java Testing: Debug test class in buffer"
keymap.set("n", "<leader>jtm", ":JavaTestRunCurrentMethod<CR>", opts) keymap.set("n", "<leader>jdc", ":JavaTestDebugCurrentClass<CR>", opts)
opts.desc = "Java Testing: Debug current method in buffer" opts.desc = "Java Testing: Run current method in buffer"
keymap.set("n", "<leader>jdm", ":JavaTestDebugCurrentMethod<CR>", opts) keymap.set("n", "<leader>jtm", ":JavaTestRunCurrentMethod<CR>", opts)
opts.desc = "Java Testing: View last report" opts.desc = "Java Testing: Debug current method in buffer"
keymap.set("n", "<leader>jtv", ":JavaTestViewLastReport<CR>", opts) keymap.set("n", "<leader>jdm", ":JavaTestDebugCurrentMethod<CR>", opts)
end
lspconfig.jdtls.setup({ opts.desc = "Java Testing: View last report"
capabilities = capabilities, keymap.set("n", "<leader>jtv", ":JavaTestViewLastReport<CR>", opts)
on_attach = java_on_attach, end
})
lspconfig.texlab.setup({ lspconfig.jdtls.setup({
cmd = { "texlab" }, capabilities = capabilities,
filetypes = { "tex", "latex", "bib" }, on_attach = java_on_attach,
root_dir = function(fname) })
return vim.loop.cwd()
end,
})
local lspconfutil = require("lspconfig/util") lspconfig.texlab.setup({
local root_pattern = lspconfutil.root_pattern("veridian.yml", ".git", ".xpr") cmd = { "texlab" },
local verilog_root_dir = function() filetypes = { "tex", "latex", "bib" },
local filename = lspconfutil.path.join(vim.loop.cwd(), fname) root_dir = function(fname)
return root_pattern(filename) or lspconfutil.path.dirname(filename) return vim.loop.cwd()
end end,
lspconfig.veridian.setup({ })
capabilities = capabilities,
on_attach = on_attach,
root_dir = verilog_root_dir,
})
lspconfig.verible.setup({ local lspconfutil = require("lspconfig/util")
-- cmd = { 'verible-verilog-ls', '--rules_config=/home/janis/.config/nvim/util/verible-conf.json' }, local root_pattern = lspconfutil.root_pattern("veridian.yml", ".git", ".xpr")
cmd = { "verible-verilog-ls", "--rules=-no-trailing-spaces", "" }, local verilog_root_dir = function()
capabilities = capabilities, local filename = lspconfutil.path.join(vim.loop.cwd(), fname)
on_attach = on_attach, return root_pattern(filename) or lspconfutil.path.dirname(filename)
root_dir = verilog_root_dir, end
}) lspconfig.veridian.setup({
end, capabilities = capabilities,
on_attach = on_attach,
root_dir = verilog_root_dir,
})
lspconfig.verible.setup({
-- cmd = { 'verible-verilog-ls', '--rules_config=/home/janis/.config/nvim/util/verible-conf.json' },
cmd = { "verible-verilog-ls", "--rules=-no-trailing-spaces", "" },
capabilities = capabilities,
on_attach = on_attach,
root_dir = verilog_root_dir,
})
end,
} }