From: Andreas Louv Date: Sat, 11 Mar 2023 08:53:16 +0000 (+0100) Subject: Make it possible to provide a new name directly to "LspRename" X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=185b3bc4372ee6b8f7af1fc5ee755422d31cc4c8;p=vim-lsp.git Make it possible to provide a new name directly to "LspRename" --- diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 24f41bb..990a94e 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -687,20 +687,23 @@ enddef # Rename a symbol # Uses LSP "textDocument/rename" request -export def Rename() +export def Rename(a_newName: string) var lspserver: dict = buf.CurbufGetServerChecked() if lspserver->empty() return endif - var sym: string = expand('') - var newName: string = input($"Rename symbol '{sym}' to: ", sym) + var newName: string = a_newName if newName == '' - return - endif + var sym: string = expand('') + newName = input($"Rename symbol '{sym}' to: ", sym) + if newName == '' + return + endif - # clear the input prompt - echo "\r" + # clear the input prompt + echo "\r" + endif lspserver.renameSymbol(newName) enddef diff --git a/doc/lsp.txt b/doc/lsp.txt index bf4cfad..fb4718a 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -527,10 +527,12 @@ can map these commands to keys and make it easier to invoke them. language servers support this feature. *:LspRename* -:LspRename Rename the current symbol. You will be prompted to - enter the new name for the symbol. You can press - or enter an empty string in the prompt to cancel the - operation. +:LspRename [newName] Rename the current symbol. + + When [newName] is not given, then you will be prompted + to enter the new name for the symbol. You can press + or enter an empty string in the prompt to cancel + the operation. *:LspSelectionExpand* :LspSelectionExpand Visually select the region of the symbol under the diff --git a/plugin/lsp.vim b/plugin/lsp.vim index 8bf146b..f374cfc 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -105,7 +105,7 @@ command! -nargs=0 -bar LspPeekDefinition lsp.GotoDefinition(v:true, ) command! -nargs=0 -bar LspPeekImpl lsp.GotoImplementation(v:true, ) command! -nargs=0 -bar LspPeekReferences lsp.ShowReferences(v:true) command! -nargs=0 -bar LspPeekTypeDef lsp.GotoTypedef(v:true, ) -command! -nargs=0 -bar LspRename lsp.Rename() +command! -nargs=? -bar LspRename lsp.Rename() command! -nargs=0 -bar LspSelectionExpand lsp.SelectionExpand() command! -nargs=0 -bar LspSelectionShrink lsp.SelectionShrink() command! -nargs=1 -complete=customlist,LspServerDebugComplete -bar LspServerDebug lsp.ServerDebug() diff --git a/test/unit_tests.vim b/test/unit_tests.vim index 777649a..c07b273 100644 --- a/test/unit_tests.vim +++ b/test/unit_tests.vim @@ -445,6 +445,25 @@ def Test_LspRename() } END assert_equal(expected, getline(1, '$')) + + cursor(1, 1) + search('counter') + LspRename countvar + var expected2: list =<< trim END + void F1(int countvar) + { + countvar = 20; + + ++countvar; + } + + void F2(int count) + { + count = 5; + } + END + assert_equal(expected2, getline(1, '$')) + sleep 100m bw! # empty file