diff options
| author | Marcelo <setanta@gmail.com> | 2025-03-03 21:05:55 -0300 |
|---|---|---|
| committer | Marcelo Lira <setanta@gmail.com> | 2025-03-07 02:15:25 -0300 |
| commit | c78361a6155dd53cd1098f7fdf33acfea20dc903 (patch) | |
| tree | e13b8065c4a1180f3b1d483676b55af4cba2ee4c /lua/config/plugins/lsp.lua | |
Initial commit.
Diffstat (limited to 'lua/config/plugins/lsp.lua')
| -rw-r--r-- | lua/config/plugins/lsp.lua | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/lua/config/plugins/lsp.lua b/lua/config/plugins/lsp.lua new file mode 100644 index 0000000..16e785d --- /dev/null +++ b/lua/config/plugins/lsp.lua @@ -0,0 +1,106 @@ +return { + { + "neovim/nvim-lspconfig", + dependencies = { + "saghen/blink.cmp", + }, + opts = { + servers = { + clangd = { + cmd = { + "clangd", + "--header-insertion=iwyu", + "--background-index", + "--clang-tidy", + "--log=verbose", + }, + filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto" }, + single_file_support = true, + }, + cssls = {}, + html = {}, + jsonls = {}, + lua_ls = { + settings = { + Lua = { + runtime = { + version = "LuaJIT", + }, + diagnostics = { + globals = { + "vim", + "require", + }, + }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + }, + telemetry = { + enable = false, + }, + }, + }, + }, + marksman = {}, + solargraph = { + cmd = { + vim.fn.expand('~/.local/share/nvim/mason/bin/solargraph'), + 'stdio', + }, + }, + ts_ls = {}, + }, + }, + + config = function(_, opts) + local lspconfig = require("lspconfig") + local blink = require("blink.cmp") + + for server, config in pairs(opts.servers) do + config.capabilities = blink.get_lsp_capabilities() + lspconfig[server].setup(config) + end + + vim.api.nvim_create_autocmd("LspAttach", { + callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + if not client then return end + + vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "Jumps to definition", buffer = args.buf }) + vim.keymap.set("n", "gD", vim.lsp.buf.declaration, { desc = "Jumps to declaration", buffer = args.buf }) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, { desc = "Lists all implementations", buffer = args.buf }) + + vim.keymap.set("n", "<Leader>cf", function() vim.lsp.buf.format({ async = true, buffer = args.buf }) end, + { desc = "Formats a buffer", buffer = args.buf }) + vim.keymap.set("v", "<C-f>", function() vim.lsp.buf.format({ async = true, buffer = args.buf }) end, + { desc = "Formats a buffer", buffer = args.buf }) + + -- Disabled, kept temporarily here just for reference + if false and vim.bo.filetype == "lua" then + if client.supports_method("textDocument/formatting") then + vim.api.nvim_create_autocmd("BufWritePre", { + buffer = args.buf, + callback = function() + vim.lsp.buf.format({ bufnr = args.buf, id = client.id }) + end, + }) + end + end + end + }) + + vim.diagnostic.config({ + underline = true, + virtual_text = { prefix = " ●", }, + signs = { + text = { + [vim.diagnostic.severity.ERROR] = "", + [vim.diagnostic.severity.WARN] = "", + [vim.diagnostic.severity.INFO] = "", + [vim.diagnostic.severity.HINT] = "", + }, + }, + }) + end, + }, +} |
