News

Python in VS Code Does Browser-Based Editing via 'github.dev' Trick

New functionality to quickly launch Visual Studio Code in the browser is being infused into more dev tooling, including the Python extension that uses the Pylance language server for language-specific intelligence.

The new capability surprised hundreds of developers recently ("One-Click VS Code in Browser from GitHub Repo ('How Did I Not Know This?')") when GitHub introduced the github.dev feature in preview, providing the ability to instantly open up VS Code in a browser in order to edit the source code found in any repository (and you just got a taste of the experience if you clicked on that github.dev link). That's done simply by pressing the period (.) key to bring up the browser-based VS Code environment from any repo, or changing the URL from "github.com" to "github.dev." The capability is part of GitHub Codespaces, basically a cloud-hosted VS Code environment, but it was only announced recently via social media posts.

"It's a quick way to edit and navigate code," says GitHub, which is owned by Microsoft. "It's especially useful if you want to edit multiple files at a time or take advantage of all the powerful code editing features of Visual Studio Code when making a quick change."

Web-Based Editor in Animated Action
[Click on image for larger, animated GIF view.] Web-Based Editor in Animated Action (source: GitHub).

Documentation says the web-based editor provides many of the benefits of VS Code, including search, syntax highlighting and a source control view.

Syntax highlighting in Python code -- along with other language-specific "smartness" -- is provided in Microsoft's Python extension for VS Code via the Pylance language server, and that's where the new functionality is brought into play in the August 2021 update to the hugely popular Python extension.

"We are delighted to announce that as of this release you can enjoy the performant editing experience of Pylance in the browser via github.dev," said Savannah Ostrowski, a program manager for Pylance and Python in Visual Studio, in a Sept. 2 blog post. "If you are unfamiliar with github.dev, you can head over to any repo, pull request, or file on GitHub and hit '.' on your keyboard (or change the URL to github.dev) to give it a shot!"

Support for core editing features when exploring a new codebase or making minor edits to Python code include:

Ostrowski said one issue with the feature is that developers can't yet run Python code in the browser, but "you can do so in a Jupyter notebook with the vscode-pyolite extension (in preview), made by one of our team members!"

Developers can provide feedback on the new github.dev feature in the Pylance issue tracker.

Other highlights of the update include:

  • Revamped testing interface: By leveraging the built-in test explorer in VS Code, the team crossed off 55 GitHub repo issues with an overhaul of the testing UI touching on test discovery, navigation, configuration, and running and debugging tests.
  • New button for running and debugging files on the editor: Now, when pressing the editor's Run button, developers will see debugging files as an option. Choosing that option will run the active Python file in the terminal by default, but debugging is also an option developers can take with a couple quick clicks.
    Run and Debug in Animated Action
    [Click on image for larger, animated GIF view.] Run and Debug in Animated Action (source: Microsoft).
  • Microsoft Python Language Server end of life November 2021: After Pylance was made the default language server for Python in VS Code back in May, Ostrowski said it's now being used by nearly all coders. After deprecation is finalized in November, the legacy Microsoft Python Language Server repository will be archived, though developers will still be able to fork and build upon its codebase.
  • Limited IntelliSense support for Python 2.7 starting in October 2021: "Starting with the 2021.10 of the Python extension, we will only offer support for Jedi 0.18 and higher, and no longer ship support for Jedi 0.17. We will also be removing support for ctags and rope at the same time."

The Python extension in the VS Code marketplace is by far the most popular tool available for Microsoft's open source-based, cross-platform code editor. As of this writing, it has been installed some 41.6 million times while the No. 2 offering, C/C++, shows fewer than 23 million downloads. Pylance comes bundled with the Python tool as an optional dependency, along with the Jupyter extension.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus

Featured

Upcoming Events