Skip to content

Commit 9b45d86

Browse files
authored
feat(ts_ls): add _typescript.rename handler #3779
This handler is used when performing certain code actions such as extracting functions or types. The language server asks the editor to prompt for a rename for the newly created function or type.
1 parent a9d8e65 commit 9b45d86

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lsp/ts_ls.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,19 @@ return {
7878
'typescript.tsx',
7979
},
8080
root_markers = { 'tsconfig.json', 'jsconfig.json', 'package.json', '.git' },
81+
handlers = {
82+
-- handle rename request for certain code actions like extracting functions / types
83+
['_typescript.rename'] = function(_, result, ctx)
84+
local client = vim.lsp.get_client_by_id(ctx.client_id)
85+
vim.lsp.util.show_document({
86+
uri = result.textDocument.uri,
87+
range = {
88+
start = result.position,
89+
['end'] = result.position,
90+
},
91+
}, client.offset_encoding)
92+
vim.lsp.buf.rename()
93+
return vim.NIL
94+
end,
95+
},
8196
}

0 commit comments

Comments
 (0)