Python in Visual Studio Code – July 2021 Release
We are pleased to announce that the July 2021 release of the Python Extension for Visual Studio Code is now available. You can download the Python extension from the Marketplace, or install it directly from the extension gallery in Visual Studio Code. If you already have the Python extension installed, you can also get the latest update by restarting Visual Studio Code. You can learn more about Python support in Visual Studio Code in the documentation.
These are some of the notable changes introduced in this release:
- A faster way to configure project roots via a new Pylance quick fix
- Selecting a Python interpreter no longer changes settings
- New debugger features: step into targets and function breakpoints
If you are interested, you can check the full list of improvements in our changelog.
A faster way to configure project roots
We’re excited to announce that we’ve added a new quick fix to to allow you to more quickly configure your Python project roots!
A common issue we’ve heard developers experience in VS Code is seeing diagnostics (or yellow squiggles) under import statements when they open new projects and then not knowing what to do to resolve them.
Previously, configuring project roots would require setting python.analysis.extraPaths to tell Pylance what search paths to use for import resolution (that is, for finding the paths of packages that are imported to get the information necessary to provide IntelliSense features). Now, you’re able to skip the step of manually fiddling with your settings.json and trying to figure out the right search paths to add to extraPaths and instead have Pylance guide you via the editor.
You can now hover over the diagnostic on the import statement and either click the lightbulb icon or “Quick Fix…” in the tooltip and Pylance will suggest search paths to add to python.analysis.extraPaths, where appropriate.
Selecting a Python interpreter no longer modifies workspace settings
Previously, selecting or changing a Python interpreter with the Python extension would update a setting called “python.pythonPath” with the path to the interpreter as its value. But because the interpreter path is often very specific to a machine, that behavior was problematic for those who wanted to share their VS Code workspace settings in a GitHub repo, for example, as reported in our issue tracker.
To make the interpreter information system-agnostic, changes to the selected interpreter will no longer cause modifications to your settings.json. The Python extension will keep storing the interpreter information per workspace, but in internal storage. If you want to see the path to the selected interpreter, you can run the “Python: Select Interpreter“ command and check the value of the “current” field. You can also open the Python output panel to retrieve the path.
If you still want to define an interpreter path to be used by the Python extension by default in your settings.json, you can set the “python.defaultInterpreterPath” instead. When set on the workspace scope, the value of this setting will define which interpreter the Python extension will select when it loads the workspace for the first time (and for the first time only). This setting will not be modified automatically, which means that the Python extension will not change its value when a different interpreter is specified in the setting.
You can also set “python.defaultInterpreterPath” on the User scope to define the path to an interpreter that you wish to be selected on the first time you open any workspaces.
If you have the “python.pythonPath” setting defined on your workspace, its value will be used to update the selected interpreter in the internal storage. However, that will happen only on the first time this newest version of the Python extension loads – further changes to this setting will not be picked up.
Two new debugger features: step into targets and function breakpoints
We’re excited to be introducing a new feature to improve your productivity when debugging your Python code!
The first one is the ability to choose which targets to step into when there is more than one possible option. Take the example code below:
Before, if all you wanted was to step into the generate_wordcloud call, you would need to step into (and then immediately step out) of the parse_content, Image.open and np.array calls.
Now, when the debugger stops at a breakpoint on a line that has multiple function calls, you can specify which one you want to step into by right-clicking on the editor and selecting “step into targets”:
You can then select which target you would like to step into. In our case, that would be the generate_wordcloud method.
The other exciting new feature we’re bringing in this release is function breakpoints. If you’re interested in inspecting just a certain function’s behavior, you can specify its name on the breakpoint window so that the debugger will stop its execution once it reaches the function:
For example, if we wanted the debugger to stop once the execution reached the parse_content function, we would add its name in the breakpoints window. Function breakpoints are represented by a red triangle, like in the image below:
Other Changes and Enhancements
We have also added small enhancements and fixed issues requested by users that should improve your experience working with Python in Visual Studio Code. Some notable changes include:
- Make test explorer only show file/folder names on nodes. (thanks bobwalker99) (#16368)
- Bug fixes for Poetry support: the poetryPath setting will correctly apply system variable substitutions, and the Jupyter Notebook extension will install any missing dependencies using Poetry or Pipenv if those are the selected environments. (thanks Anthony Shaw) (#16607, #16615)
- Add support for renaming modules with Jedi (thanks Anupama Nadig!) (jedi-language-server/#134)
Be sure to download the Python extension for Visual Studio Code now to try out the above improvements. If you run into any problems or have suggestions, please file an issue on the Python VS Code GitHub page.
you are doing nothing for c#(asp.net core) in vs code. no good extension, no intellisence, eveything extension is improving except asp.net core. why?
And Perl? I have 3rd party plug-ins but official support for a language that people are still using would be nice.