Search code examples
pythonvisual-studio-codevscode-extensionslanguage-server-protocol

Is vscode-python extension for VSCode is a Language Service or just an extension only?


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!


Solution

  • 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:

    https://github.com/Microsoft/vscode-python/blob/c976b6c98e34e041b7ee826ec22f9820ba90f8ac/src/client/providers/renameProvider.ts

    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)]
    )