Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions lua/plugins/nvim-lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,21 +225,31 @@ return {
end

if vim.fn.executable("typescript-language-server") == 1 then
-- Create the LspOrganize command once globally to avoid duplication warnings
-- Use force = true to allow recreation on config reload
vim.api.nvim_create_user_command("LspOrganize", function()
-- Check if a TypeScript LSP client is attached to the current buffer
local clients = vim.lsp.get_clients({ bufnr = 0, name = "ts_ls" })
if #clients == 0 then
vim.notify("No TypeScript LSP client attached to current buffer", vim.log.levels.WARN)
return
end

vim.lsp.buf.execute_command({
command = "_typescript.organizeImports",
arguments = { vim.api.nvim_buf_get_name(0) },
title = "",
})
end, { desc = "Organize Imports", force = true })

lspconfig.ts_ls.setup({
on_attach = function(client, bufnp)
on_attach(client, bufnp)
on_attach = function(client, bufnr)
on_attach(client, bufnr)

client.server_capabilities.documentFormattingProvider = false
client.server_capabilities.documentRangeFormattingProvider = false
local keymap_opts = { buffer = bufnp, noremap = true, silent = true }
local keymap_opts = { buffer = bufnr, noremap = true, silent = true }
vim.keymap.set("n", "<leader>xo", "<cmd>LspOrganize<CR>", keymap_opts)
vim.api.nvim_create_user_command("LspOrganize", function()
vim.lsp.buf.execute_command({
command = "_typescript.organizeImports",
arguments = { vim.api.nvim_buf_get_name(0) },
title = "",
})
end, { desc = "Organize Imports" })
end,
capabilities = caps,
filetypes = {
Expand Down