add lsp_organize_imports util function
thanks to this guy https://stackoverflow.com/a/67851340/13725946
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
vim.cmd([[
|
||||||
|
command! OrganizeImports :lua require('user.utils').lsp_organize_imports()<CR>
|
||||||
|
]])
|
||||||
|
|||||||
@@ -81,3 +81,6 @@ nmap("<leader>do", ":lopen<CR>")
|
|||||||
|
|
||||||
-- Git
|
-- Git
|
||||||
nmap("<leader>gg", ":G<CR>")
|
nmap("<leader>gg", ":G<CR>")
|
||||||
|
|
||||||
|
-- Refactoring
|
||||||
|
nmap("<leader>ri", ":lua require('user.utils').lsp_organize_imports()<CR>")
|
||||||
|
|||||||
@@ -124,4 +124,18 @@ M.goto_global_definition = function()
|
|||||||
vim.api.nvim_win_set_cursor(0, { startLine, startCol })
|
vim.api.nvim_win_set_cursor(0, { startLine, startCol })
|
||||||
end
|
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
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user