From c43196a300c77491ded16111edbaa4386b8a3ae7 Mon Sep 17 00:00:00 2001 From: Alexander Roso Date: Mon, 9 Feb 2026 09:07:19 +0100 Subject: [PATCH] create "organize imports" mapping for TS on lsp attach --- after/ftplugin/typescript.lua | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/after/ftplugin/typescript.lua b/after/ftplugin/typescript.lua index bc3858d..32e9eb2 100644 --- a/after/ftplugin/typescript.lua +++ b/after/ftplugin/typescript.lua @@ -1,8 +1,18 @@ vim.o.textwidth = 120 -vim.keymap.set("n", "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", "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", "s", function() require("nvim-quick-switcher").toggle("tsx", "scss") end, { buffer = true })