]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Make it possible to provide a new name directly to "LspRename"
authorAndreas Louv <andreas@louv.dk>
Sat, 11 Mar 2023 08:53:16 +0000 (09:53 +0100)
committerAndreas Louv <andreas@louv.dk>
Sat, 11 Mar 2023 17:29:10 +0000 (18:29 +0100)
autoload/lsp/lsp.vim
doc/lsp.txt
plugin/lsp.vim
test/unit_tests.vim

index 24f41bb6dbaea429a5a1f90f3423fd11057d4ab0..990a94e57ffa62d2e0072c142c8af2892b55e036 100644 (file)
@@ -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<any> = buf.CurbufGetServerChecked()
   if lspserver->empty()
     return
   endif
 
-  var sym: string = expand('<cword>')
-  var newName: string = input($"Rename symbol '{sym}' to: ", sym)
+  var newName: string = a_newName
   if newName == ''
-    return
-  endif
+    var sym: string = expand('<cword>')
+    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
index bf4cfade70aeee8a3171c3461ec91f267bd2fd47..fb4718aa3150248b1d11bca06a42efb0d055d03a 100644 (file)
@@ -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 <Esc>
-                       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
+                       <Esc> or enter an empty string in the prompt to cancel
+                       the operation.
 
                                                *:LspSelectionExpand*
 :LspSelectionExpand    Visually select the region of the symbol under the
index 8bf146b8b2244f77be7a0f010d03ac7b549e2223..f374cfca33378a453caba3ad501811d89d5380bd 100644 (file)
@@ -105,7 +105,7 @@ command! -nargs=0 -bar LspPeekDefinition lsp.GotoDefinition(v:true, <q-mods>)
 command! -nargs=0 -bar LspPeekImpl lsp.GotoImplementation(v:true, <q-mods>)
 command! -nargs=0 -bar LspPeekReferences lsp.ShowReferences(v:true)
 command! -nargs=0 -bar LspPeekTypeDef lsp.GotoTypedef(v:true, <q-mods>)
-command! -nargs=0 -bar LspRename lsp.Rename()
+command! -nargs=? -bar LspRename lsp.Rename(<q-args>)
 command! -nargs=0 -bar LspSelectionExpand lsp.SelectionExpand()
 command! -nargs=0 -bar LspSelectionShrink lsp.SelectionShrink()
 command! -nargs=1 -complete=customlist,LspServerDebugComplete -bar LspServerDebug lsp.ServerDebug(<q-args>)
index 777649a6d8c48c7b6a257c0253219fae2bc7d090..c07b273e4d5c0230ec0898a6660879903f41d4e9 100644 (file)
@@ -445,6 +445,25 @@ def Test_LspRename()
     }
   END
   assert_equal(expected, getline(1, '$'))
+
+  cursor(1, 1)
+  search('counter')
+  LspRename countvar
+  var expected2: list<string> =<< 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