chore: some qol crap

This commit is contained in:
Mariano Z. 2025-04-02 18:07:53 -03:00
parent 867159343a
commit 6fb744cdae
Signed by: marianozunino
GPG key ID: 4C73BAD25156DACE
34 changed files with 433 additions and 598 deletions

View file

@ -1,68 +0,0 @@
return {
"pmizio/typescript-tools.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"neovim/nvim-lspconfig",
},
ft = { "typescript", "javascript", "jsx", "tsx", "json" },
config = function()
local lsp_common = require("plugins.lsp").get_common_config()
local ts_api = require("typescript-tools.api")
local original_on_attach = lsp_common.on_attach
lsp_common.on_attach = function(client, bufnr)
original_on_attach(client, bufnr)
vim.keymap.set("n", "<leader>ca", function()
local diagnostics = vim.diagnostic.get(0, { lnum = vim.fn.line(".") - 1 })
local context = { diagnostics = diagnostics }
local params = vim.lsp.util.make_range_params(0)
params.context = context
params = vim.tbl_extend("force", {}, params)
vim.lsp.buf_request(bufnr, "textDocument/codeAction", params, function(err, result, ctx)
local actions = result or {}
table.insert(actions, { title = "Organize Imports", command = "typescript.custom.organize_imports" })
table.insert(actions, { title = "Fix All", command = "typescript.custom.fix_all" })
table.insert(actions, { title = "Add Missing Imports", command = "typescript.custom.add_missing_imports" })
table.insert(actions, { title = "Remove Unused", command = "typescript.custom.remove_unused" })
vim.ui.select(actions, {
prompt = "Code Actions",
format_item = function(action)
return action.title
end,
}, function(action)
if not action then
return
end
if action.command == "typescript.custom.organize_imports" then
pcall(ts_api.organize_imports)
elseif action.command == "typescript.custom.fix_all" then
pcall(ts_api.fix_all)
elseif action.command == "typescript.custom.add_missing_imports" then
pcall(ts_api.add_missing_imports)
elseif action.command == "typescript.custom.remove_unused" then
pcall(ts_api.remove_unused)
else
if action.edit or type(action.command) == "table" then
if action.edit then
vim.lsp.util.apply_workspace_edit(action.edit, "utf-8")
end
if type(action.command) == "table" then
vim.lsp.buf.execute_command(action.command)
end
end
end
end)
end)
end, { buffer = bufnr, desc = "Code Actions" })
end
require("typescript-tools").setup(vim.tbl_deep_extend("force", lsp_common, {
settings = {
separate_diagnostic_server = true,
publish_diagnostic_on = "insert_leave",
expose_as_code_action = {},
},
}))
end,
}

View file

@ -2,11 +2,13 @@ local M = {
"neovim/nvim-lspconfig",
dependencies = {
"saghen/blink.cmp",
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"WhoIsSethDaniel/mason-tool-installer.nvim",
{ "j-hui/fidget.nvim", opts = {} },
require("plugins.lsp.extras.lazydev"),
require("plugins.lsp.extras.gopher"),
require("plugins.lsp.extras.typescript"),
},
}
@ -93,6 +95,9 @@ function M.config()
local ensure_installed = {
-- LSP servers
"gopls",
"jsonls",
"lua_ls",
"yamlls",
"graphql-language-service-cli",
"html-lsp",
"htmx-lsp",
@ -101,6 +106,7 @@ function M.config()
"omnisharp",
"yaml-language-server",
"svelte-language-server",
"vtsls",
-- Formatters
"prettierd",
@ -115,27 +121,12 @@ function M.config()
"templ",
}
-- Install missing tools
local registry = require("mason-registry")
for _, tool in ipairs(ensure_installed) do
if not registry.is_installed(tool) then
vim.cmd("MasonInstall " .. tool)
end
end
require("mason-tool-installer").setup({ ensure_installed = ensure_installed })
-- Set up Mason LSP config
require("mason-lspconfig").setup({
automatic_installation = true,
ensure_installed = {
"gopls",
"html",
"htmx",
"jsonls",
"lua_ls",
"omnisharp",
"yamlls",
"graphql",
},
ensure_installed = {}, -- explicitly set to an empty table (populated via mason-tool-installer)
automatic_installation = false,
handlers = {
function(server_name)
local base_opts = M.get_common_config()