# 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
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
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>)
}
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