Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto Import and Refactor (Move) function from one file to another in vscode

Pycharm provides:

  • Move functions/classes/variables from one file to another via refactor > Move (f6-keyboard shortcut)

  • Import missing imports in the current file

Is the same available in vscode? I tried searching and came across a pull request for auto import here. Couldn't find anything on move refactoring though.

Is it currently possible to do so in vscode via any extensions etc?

like image 898
Adarsh Avatar asked May 18 '19 08:05

Adarsh


People also ask

Can you Refactor in VS code?

Visual Studio Code supports refactoring operations (refactorings) such as Extract Method and Extract Variable to improve your code base from within your editor.

How do I move files in Vscode?

You can also move file with using console (for example PowerShell or Git Bash) in Code. Recently I have I habit to move files or folders in sidebar, via ctrl + x (cut) and ctrl + v (paste), after this action Code automatically updates imports. Drag & drop method also works.


2 Answers

The first is not available in the Python extension for VS Code and the latter is a feature request. If you would like to see auto imports implemented, please go to that issue and upvote it.

like image 87
Brett Cannon Avatar answered Oct 23 '22 01:10

Brett Cannon


Auto-Import for (new) missing imports is now available with PyLance.

like image 35
djm Avatar answered Oct 23 '22 00:10

djm