Change lsp config

This commit is contained in:
Marcelo Jacobus 2025-09-19 16:30:29 -03:00
parent fb2a9d213a
commit 2d12fcf604

View file

@ -1,38 +1,3 @@
-- 1. Setup for all requested language servers:
-- - Ruby (ruby_lsp)
-- - TypeScript/JavaScript (ts_ls)
-- - HTML (html)
-- - CSS (cssls)
-- - Dart (dartls)
--
-- 2. Standard LSP keybindings:
-- - gD: Go to declaration
-- - gd: Go to definition
-- - K: Hover documentation
-- - gi: Go to implementation
-- - <C-k>: Signature help
-- - <leader>wa: Add workspace folder
-- - <leader>wr: Remove workspace folder
-- - <leader>wl: List workspace folders
-- - <leader>D: Type definition
-- - <leader>rn: Rename
-- - <leader>ca: Code actions
-- - gr: Find references
-- - <leader>f: Format code
return {
{
"neovim/nvim-lspconfig",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
},
config = function()
local lspconfig = require('lspconfig')
-- Global LSP settings
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- LSP keymaps
local on_attach = function(client, bufnr) local on_attach = function(client, bufnr)
local opts = { noremap = true, silent = true, buffer = bufnr } local opts = { noremap = true, silent = true, buffer = bufnr }
@ -58,71 +23,33 @@ return {
end, opts) end, opts)
end end
-- Custom Diagnostics Keymaps local config = function(_, opts)
vim.keymap.set('n', '<leader>cd', vim.diagnostic.open_float, { desc = 'Line Diagnostics' }) local lspconfig = require('lspconfig')
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Previous Diagnostic' }) for server, config in pairs(opts.servers) do
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Next Diagnostic' }) -- passing config.capabilities to blink.cmp merges with the capabilities in your
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Set Loclist Diagnostics' }) -- `opts[server].capabilities, if you've defined it
config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities)
lspconfig[server].setup(config)
end
end
-- Ruby LSP return {
lspconfig.ruby_lsp.setup({ {
-- cmd = { vim.fn.expand("~/.asdf/shims/ruby"), "-S", "ruby-lsp" }, "neovim/nvim-lspconfig",
capabilities = capabilities, dependencies = {
on_attach = on_attach, -- "hrsh7th/cmp-nvim-lsp",
}) 'saghen/blink.cmp'
-- TypeScript/JavaScript LSP
lspconfig.ts_ls.setup({
capabilities = capabilities,
on_attach = on_attach,
})
-- HTML LSP
lspconfig.html.setup({
capabilities = capabilities,
on_attach = on_attach,
})
-- CSS LSP
lspconfig.cssls.setup({
capabilities = capabilities,
on_attach = on_attach,
})
-- Dart LSP (Flutter)
lspconfig.dartls.setup({
capabilities = capabilities,
on_attach = on_attach,
})
-- NOTE: Not sure this works
-- Auto-import missing imports on save for JS/TS
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = { "*.ts", "*.tsx", "*.js", "*.jsx" },
callback = function()
local params = {
context = {
only = { "source.addMissingImports.ts" },
}, },
opts = {
servers = {
ruby_lsp = { on_attach = on_attach },
ts_ls = { on_attach = on_attach },
html = { on_attach = on_attach },
cssls = { on_attach = on_attach },
dartls = { on_attach = on_attach },
lua_ls = { on_attach = on_attach },
} }
local clients = vim.lsp.get_active_clients({ name = "ts_ls" }) },
for _, client in ipairs(clients) do config = config,
if client.supports_method("textDocument/codeAction") then
vim.lsp.buf_request(0, "textDocument/codeAction", vim.lsp.util.make_range_params(), function(_, result)
if result and result[1] then
if result[1].edit then
vim.lsp.util.apply_workspace_edit(result[1].edit, client.offset_encoding or "utf-8")
end
if result[1].command then
vim.lsp.buf.execute_command(result[1].command)
end
end
end)
end
end
end,
})
end,
} }
} }