Search code examples
pythonvisual-studio-coderefactoring

Refactor code into a subfunction in VS Code


If they're a built-in function or extension in VS Code to refactor any selected code into a subfunction? Or at least to analyse the code and show all dependencies/variables that would need to be provided as function parameters. I know such a functionality from Pycharm.

My least goal would be to see in advance how much effort it would be to create a subfunction - or if it is meaningful at all (without providing dozens of parameters).

I am talking about Python.


Solution

  • You can read document about Python Refactoring.

    The Python extension adds the following refactoring functionalities: Extract Variable, Extract Method and Rename Module. It also supports extensions that implement additional refactoring features such as Sort Imports.

    enter image description here

    After selecting the code, you can click on the yellow light bulb on the left to automatic refactoring.