create "organize imports" mapping for TS on lsp attach

This commit is contained in:
Alexander Roso 2026-02-09 09:07:19 +01:00
parent 7f67cabd57
commit c43196a300

View file

@ -1,8 +1,18 @@
vim.o.textwidth = 120
vim.keymap.set("n", "<leader>o", function()
vim.lsp.buf.execute_command({ command = "_typescript.organizeImports", arguments = { vim.fn.expand("%:p") } })
end, { desc = "Organize imports" })
local function on_ts_ls_attach(ev)
vim.keymap.set("n", "<leader>o", function()
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if not client then return end
return client:exec_cmd({
title = "Organize imports",
command = "_typescript.organizeImports",
arguments = { vim.api.nvim_buf_get_name(ev.buf) }
}, { bufnr = ev.buf })
end, { noremap = true, silent = true, buffer = ev.buf })
end
vim.api.nvim_create_autocmd("LspAttach", { callback = on_ts_ls_attach })
vim.keymap.set("n", "<leader>s", function()
require("nvim-quick-switcher").toggle("tsx", "scss")
end, { buffer = true })