Python in Visual Studio Code – April 2018 Release
We are pleased to announce that the April 2018 release of the Python Extension for Visual Studio Code is now available from the marketplace and the gallery. You can download the Python extension from the marketplace, or install it directly from the extension gallery in Visual Studio Code. You can learn more about Python support in Visual Studio Code in the VS Code documentation.
In this release we have closed a total of 110 issues including remote debugging support in the Preview debugger, and enhancements to running Python code in the terminal.
Improvements to Running Python Code in the Terminal
We’ve made various improvements that make it easier to run Python code in the terminal.
A Ctrl+Enter keyboard shortcut has been added for the “Python: Run Line/Selection in terminal” command. The command was also enhanced so that it adds and removes blank lines in indented code blocks so that they will run correctly in the terminal.
Take the following code example:
Previously this code would not have run properly in the terminal because the blank line in between the two print statements would cause an indentation error when running the second print function, and a blank line is needed to finish the indentation block before running the third print function.
Now the blank line is removed in between the two print function calls, a blank line is added before the third print function call, and the code is successfully run in the terminal when pressing Ctrl-Enter:
When using the “Python: Create Terminal” command, the focus is put into the terminal so you no longer need to use the mouse to click into the window before you start typing. The “Run Python File in Terminal” command (available on the context menu in the file explorer, or in the command palette) now saves the file before running it, avoiding confusion from running code that doesn’t match what is shown in the editor.
Remote Debugging Support in Preview Debugger
We are continuing to add features to our Preview debugger, in this release we added remote debugging capabilities. The Preview debugger was first added in the February release of the extension, and will provide significantly better debugging performance and reliability when it becomes stable.
To use remote debugging, you first need to install the preview version of ptvsd using:
pip install ptvsd --pre
Then you can start the debug server in one of two ways, by using the following command to start a python file:
python -m ptvsd --server --port 9091 --file module.py
Or you can import ptvsd into your app and start the server programmatically:
import ptvsd ptvsd.enable_attach(('0.0.0.0', 5678))
Then you can add a remote attach configuration from the debugging configuration drop-down and enter the port and IP address to use:
One improvement of remote debugging that you get with the Preview debugger is that you don’t need to use the exact same ptvsd library version on the server that is used in VS Code going forward with ptvsd 4.
To try out the preview version of the debugger, select Python Experimental debugger type when you start debugging, or when adding debug configurations.
Various Fixes and Enhancements
We have also fixed several small enhancements and fixed issues requested by users that should improve your experience working with Python in Visual Studio Code. The full list of improvements is listed in our changelog, some notable issues are:
- Fix “Go to definition” functionality across files. (#1033)
- IntelliSense improvements from upgrading to Jedi version 0.12.0 and various fixes for completions and go to definition (#1072, #178, #142, #344, #338)
- Improvements to formatting as you type when editor.formatOnType is on (#726, #1257, #1257, #1364)
- Improvements to interpreter selection/display (#1015, #1192, #1254, #1305)
- Add support for logpoints in the preview debugger. (#1306)
- Enable debugging of Jinja templates (outside of Flask apps) in the preview debugger. (#1492)
- Add support for hit count breakpoints in the preview debugger. (#1409)
- Support for using the preview debugger when debugging Python Unit Tests. To enable this, set the python.unitTest.useExperimentalDebugger setting to true. (#906)
Be sure to download the Python extension for VS Code now to try out the above improvements. If you run into any issues be sure to file an issue on the Python VS Code GitHub page.