I want to write an extension for VSCode that reuse refactor/rename function of vscode-python extension. So that, when the user executes my command, my extension will do rename on a variable of .py file. I don't know if vscode-python
is just an extension only or it's implementing Language Server Protocol LSP. And how I call the rename/refactor function of vscode-python
. Can you give me some hints? Thank you very much!
Asked
Active
Viewed 313 times
2

aviit
- 1,957
- 1
- 27
- 50
1 Answers
2
It appears that the Python extension is implementing the VSCode API directly for features such as rename, rather than using the LSP abstraction layer. See for instance its renameProvider.ts
, which implements vscode.RenameProvider
:
I don't think how it's implemented really matters to you as a caller though - It seems like you're in luck, the ability to programatically trigger a rename was added just recently and will be released soon as part of VSCode 1.25.0 / the June release:
API to programmatically begin rename (#50856)
It's also part of the release notes for the upcoming version, which give the following usage example:
vscode.commands.executeCommand(
'editor.action.rename',
[vscode.Uri.file('/my/file.abc'), new vscode.Position(14, 7)]
)

Gama11
- 31,714
- 9
- 78
- 100