VS Code PowerShell Tool Gets Editor/Debugger Revamp
Microsoft updated its PowerShell extension for Visual Studio Code, continuing a months-long re-architecture to improve the stability of its editor and debugger, which was identified as the No. 1 user request.
"Long-standing constraints in the original design of the PowerShell extension made it difficult to improve its robustness through incremental changes," said Sydney Smith of the PowerShell team in a blog post today (March 5). "Instead, over a period of six months we prioritized work to re-architect the extension with an emphasis on stability."
That effort may serve to reduce the number of complaints lodged about the tool on its marketplace listing, where a number of developers noted problems with comments such as "The powershell extension process is crashing all the time (almost every 5-10 minutes)" and "Code quality seems pretty poor and I'm constantly having problems or having the integrated terminal crashing."
The re-architected update to the PowerShell Language Support for Visual Studio Code extension comes on the heels of Microsoft shipping the latest edition of its task-based command-line shell and scripting language, PowerShell 7.
The extension provides PowerShell language services via the PowerShell language server, PowerShell Editor Services, which itself leverages the Language Server Protocol that helps VS Code and other editors smoothly support coding in a variety of programming languages, from Python to Java, by providing the language-specific "smarts" for auto complete, go to definition, find all references and other functionality.
Specifically for PowerShell, it provides:
- Syntax highlighting
- Code snippets
- IntelliSense for cmdlets and more
- Rule-based analysis provided by PowerShell Script Analyzer
- Go to Definition of cmdlets and variables
- Find References of cmdlets and variables
- Document and workspace symbol discovery
- Run selected selection of PowerShell code using F8
- Launch online help for the symbol under the cursor using Ctrl+F1
- Local script debugging and basic interactive console support!
To improve the editor/debugging experience, the team re-architected the extension's PowerShell Editor Services to use the OmniSharp language services platform, described as a family of open source projects designed to enable a great .NET experience in different editors.
"Omnisharp's architecture is more robust meaning that bugs that might once have been crashes will now be caught and logged," Smith said. "By leveraging this library we were able to greatly simplify our code and are now more compliant with language server protocol. Ultimately, we believe that these changes will significantly reduce the number crashes of the extension and improve the performance overall."
She said other benefits of the OmniSharp port include:
- Asynchronous message handling for better performance
- CodeLens requests are no longer depending on running PowerShell (greatly improving Intellisense responsiveness)
- Formatting is handled directly by the language server
In addition to performance improvements, the update includes an ISE compatibility module to help the tool work with the PowerShell Integrated Scripting Environment (ISE), which lets PowerShell users run commands and write, test, and debug scripts with a single Windows-based GUI.
"We took the documentation from our 'How to replicate the ISE experience in Visual Studio Code' doc and turned it into a switch to make the process of using Visual Studio code more familiar for Windows PowerShell ISE users," Smith said.
Another improvement involves the availability of PSReadLine, the module providing command-line editing in the PowerShell console. This was a thorny problem that was dependent upon a .NET Core 3.1 fix for the way POSIX terminal APIs are handled when starting new processes, which was included in the brand-new PowerShell 7. That fix enabled the team to make PowerShell console functionality such as syntax highlighting, multi-line editing and back search available in the VS Code integrated console across all operating systems.
A number of breaking changes are also detailed in the post, along with a plan to use extension previews to help ship future releases. "Going forward we will use preview as a vNext of our stable extension, so a preview release will take bugfixes and become the next stable release," Smith said. "After this release we plan to continue to address other outstanding issues in the extension, and use the PowerShell Preview extension as a means of increasing our release cadence."
The extension, available in the VS Code Marketplace or via in-editor extensions management, has been installed more than 2.3 million times, earning an average rating of 4.2 (0-5 scale) from 106 developers who reviewed it.
David Ramel is an editor and writer for Converge360.