More Improvements for VS Code's New Python Language Server
Microsoft announced more improvements for the new Python language server for Visual Studio Code, Pylance, specializing in rich type information.
Pylance (named after a Monty Python character) was announced as the new Python language server for VS Code back in June. It uses the Language Server Protocol to communicate with VS Code and boost IntelliSense (which provides intelligent code completion and more) with rich type information, being based on the company's Pyright static type checking tool.
While Pyright is open source, Pylance is not.
"If you are a VS Code user, we recommend that you uninstall Pyright and instead install Pylance," Microsoft says. "You will get all the benefits of Pyright and more!
"Installing both Pyright and Pylance at the same time is not recommended. If both are installed and enabled, you will see duplicate errors, hover text, and completion suggestions."
This graphic shows other differences between the two:
"To deliver an improved user experience, we've created Pylance as a brand-new language server based on Microsoft's Pyright static type checking tool," said Savannah Ostrowski, program manager for Python and its VS Code language server, at the time. "Pylance leverages type stubs (.pyi files) and lazy type inferencing to provide a highly-performant development experience. Pylance supercharges your Python IntelliSense experience with rich type information, helping you write better code, faster. The Pylance extension is also shipped with a collection of type stubs for popular modules to provide fast and accurate auto-completions and type checking."
Working with Python 3, Pylance provides:
- Signature help, with type information
- Parameter suggestions
- Code completion
- Auto-imports (as well as add and remove import code actions)
- As-you-type reporting of code errors and warnings (diagnostics)
- Code outline
- Code navigation
- Type checking mode
- Native multi-root workspace support
- IntelliCode compatibility
- Jupyter Notebooks compatibility
- Semantic highlighting
In a new post outlining the improvements to Pylance in the September update to Python in Visual Studio Code (supplied via this extension), Ostrowski detailed new improvements to the tool including:
- Support for semantic colorization in Pylance: Ostrowski said this extension on syntax highlighting helps improve the readability of code.
- Pylance auto-import improvements: "With improved auto-import completions, you can now see a clearer preview of the import statement that will be added to your file in the completion tooltip. The way that Pylance adds imports to your file has also been improved by detecting when you've already imported other submodules or functions from that module. Instead of adding a duplicate import statement to your file, Pylance will now amend the existing one by adding the symbol alphabetically in the statement, helping to keep your imports organized."
The update also includes many other minor improvements, as explained in the Sept. 23 post and changelog, which lists eight such minor enhancements as well as more than 20 fixes.
Pylance is listed as still being in the preview stage in the VS Code Marketplace, where it shows more than 166,000 installations and has earned an average 3.9 rating (0-5 scale) from 33 developers who reviewed it.
The Python extension for VS Code, meanwhile, is by far the most popular tool in the marketplace, being installed more than 25 million times.
About the Author
David Ramel is an editor and writer for Converge360.