autoload/lsp/lsp.vim | 17 ++++++++++------- doc/lsp.txt | 10 ++++++---- plugin/lsp.vim | 2 +- test/unit_tests.vim | 19 +++++++++++++++++++ diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 24f41bb6dbaea429a5a1f90f3423fd11057d4ab0..990a94e57ffa62d2e0072c142c8af2892b55e036 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 bf4cfade70aeee8a3171c3461ec91f267bd2fd47..fb4718aa3150248b1d11bca06a42efb0d055d03a 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -527,10 +527,12 @@ |:LspPeekDefinition| command. Note that not all the 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 8bf146b8b2244f77be7a0f010d03ac7b549e2223..f374cfca33378a453caba3ad501811d89d5380bd 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 777649a6d8c48c7b6a257c0253219fae2bc7d090..c07b273e4d5c0230ec0898a6660879903f41d4e9 100644 --- a/test/unit_tests.vim +++ b/test/unit_tests.vim @@ -445,6 +445,25 @@ count = 5; } 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