add lsp_organize_imports util function

thanks to this guy https://stackoverflow.com/a/67851340/13725946
This commit is contained in:
2022-03-21 15:47:29 +03:00
parent 84a4e9c1d4
commit 3ff01b554b
3 changed files with 20 additions and 0 deletions

View File

@@ -124,4 +124,18 @@ M.goto_global_definition = function()
vim.api.nvim_win_set_cursor(0, { startLine, startCol })
end
M.lsp_organize_imports = function(bufnr, timeout)
if not bufnr then
bufnr = vim.api.nvim_get_current_buf()
end
local params = {
command = "_typescript.organizeImports",
arguments = { vim.api.nvim_buf_get_name(bufnr) },
title = "",
}
vim.lsp.buf_request_sync(bufnr, "workspace/executeCommand", params, timeout or 500)
end
return M