Pylance is a fast, feature-rich language support extension for Python in Visual Studio Code, powered by the Pyright static type checker. It provides advanced type checking, auto-completions, code navigation, and other language features to enhance your Python development experience.
One of Pylance's configurable settings is python.analysis.languageServerMode
, which allows you to optimize Pylance's performance based on your development needs.
This guide explains what python.analysis.languageServerMode
is, how it affects Pylance's functionality, and how you can customize it to suit your preferences.
The python.analysis.languageServerMode
setting in Pylance offers predefined configurations to help users optimize Pylance's performance based on their development needs. It controls how many IntelliSense features Pylance provides, allowing you to choose between full language service functionality or a lightweight experience optimized for performance.
By adjusting this setting, you can strike a balance between the richness of features and the performance impact on your system.
default
(default value)light
full
-
default
: Provides a balanced experience with many useful features enabled by default. This mode ensures that Pylance delivers sufficient functionality for most users without overloading the system. Advanced features like full language analysis, indexing, and IntelliSense are enabled, allowing for a comprehensive development experience. -
light
: Designed for users seeking a lightweight, memory-efficient setup. This mode disables various features to make Pylance function more like a streamlined text editor. It is ideal for those who do not require the full breadth of IntelliSense capabilities and prefer Pylance to be as resource-friendly as possible. -
full
: Designed for users seeking the most extensive feature set. This mode enables most of Pylance's features, offering the richest IntelliSense experience. It is ideal for those who want access to the full range of available functionality. However, it will need a lot of resources, so it may not be suitable for very large projects or systems with limited hardware.
When you change the python.analysis.languageServerMode
setting, Pylance automatically adjusts several other settings to match the selected mode. Below are the default values for each mode:
Setting | default mode |
light mode |
full mode |
---|---|---|---|
python.analysis.exclude |
[] |
["**"] |
[] |
python.analysis.useLibraryCodeForTypes |
true |
false |
true |
python.analysis.enablePytestSupport |
true |
false |
true |
python.analysis.indexing |
true |
false |
true |
python.analysis.autoImportCompletions |
false |
false |
true |
python.analysis.showOnlyDirectDependenciesInAutoImport |
false |
false |
true |
python.analysis.userFileIndexingLimit |
2000 |
2000 |
-1 |
python.analysis.functionReturnTypes |
false |
false |
true |
python.analysis.pytestParameters |
false |
false |
true |
python.analysis.supportRestructuredText |
false |
false |
true |
python.analysis.supportDocstringTemplate |
false |
false |
true |
python.analysis.packageIndexDepths |
default |
default |
full |
-
python.analysis.exclude
: Specifies paths to directories or files that Pylance should not include in the analysis. Inlight
mode, it is set to["**"]
, which means Pylance will exclude all files from workspace, enabling IntelliSense support for open files only. -
python.analysis.useLibraryCodeForTypes
: When set totrue
, Pylance parses the source code of libraries when type stubs are not available. Inlight
mode, this is set tofalse
, reducing memory usage. -
python.analysis.enablePytestSupport
: Enables Pytest-specific IntelliSense features. Disabled inlight
mode to reduce resource consumption. -
python.analysis.indexing
: Indexes installed third-party libraries and user files to improve features like auto-imports and symbol searches. Disabled inlight
mode for performance optimization. -
python.analysis.autoImportCompletions
: Controls the offering of auto-imports in completions. Enabled infull
mode to provide a richer development experience. -
python.analysis.showOnlyDirectDependenciesInAutoImport
: Infull
mode, only direct dependencies declared inrequirements.txt
orpyproject.toml
are shown in auto-import suggestions, improving the relevance of suggestions. -
python.analysis.userFileIndexingLimit
: Limits the number of user files indexed in the workspace. Infull
mode, there is no limit (-1
), allowing comprehensive indexing of all files. -
python.analysis.functionReturnTypes
: Enables inlay hints for function return types infull
mode, providing additional type information during development. -
python.analysis.pytestParameters
: Enables inlay hints for Pytest function parameters infull
mode, enhancing test development support. -
python.analysis.supportRestructuredText
: Enables support for reStructuredText in docstrings infull
mode, allowing for richer documentation rendering. -
python.analysis.supportDocstringTemplate
: Enables support for docstring generation infull
mode, facilitating better code documentation. -
python.analysis.packageIndexDepths
: Used to override how many levels under installed packages to index on a per-package basis. By default, only top-level modules are indexed.- Default value:
or in
[ { "name": "sklearn", "depth": 2 }, { "name": "matplotlib", "depth": 2 }, { "name": "scipy", "depth": 2 }, { "name": "django", "depth": 2 }, { "name": "flask", "depth": 2 }, { "name": "fastapi", "depth": 2 } ]
full
mode[ { "name": "", "depth": 4, "includeAllSymbols": true } ]
In
full
mode, this ensures comprehensive indexing of submodules, improving features like auto-import and symbol searches for deeply nested packages. For more detail, please refer to the link above. - Default value:
These settings can be individually customized to override the defaults for each mode.
- Open Settings: Click on the gear icon in the lower-left corner of Visual Studio Code and select Settings.
- Search for the Setting: Type
python.analysis.languageServerMode
in the search bar. - Modify the Setting: Choose
default
,light
, orfull
from the dropdown menu.
Alternatively, you can edit your settings.json
file directly:
- Open Settings (JSON): Open the command palette and type
Preferences: Open Settings (JSON)
. - Add or Modify the Setting:
"python.analysis.languageServerMode": "light"
-
light
- Large Projects: Improves performance by analyzing only open files, reducing resource usage.
- Limited Resources: Suitable for systems with low memory or CPU power.
- Quick Edits: Ideal if you don't need advanced features and just need a simple editor setup.
-
default
- Balanced Performance: Offers a good balance of features and performance, suitable for most users.
- General Development: Ideal for regular Python development with IntelliSense and type checking features enabled by default.
-
full
- Comprehensive Features: Ideal for those who need access to the full range of IntelliSense and analysis features.
- High Resource Availability: Suitable for systems with sufficient memory and CPU power to handle more extensive analysis.
A: Full
mode provides the most extensive set of features, including advanced IntelliSense, type checking, comprehensive indexing, and auto-imports. This mode is ideal if you need full language support, especially for complex projects. However, it requires a lot of system resources, such as memory and CPU power, which means it may not be suitable for very large projects or systems with limited hardware. If your system struggles with performance issues while using full
mode, consider switching to default
or light
mode.
A: In light
mode, Pylance does not analyze closed files, perform indexing, extract type information from library code, or provide Pytest support. This reduces resource usage but limits IntelliSense features like auto-import suggestions, workspace-wide code navigation, find all references, and multi-file rename. Editor features such as completion, hover, and go-to definition will still work, but third-party library symbols may be unavailable if stubs or type information are missing, which can also affect diagnostics.
A: Yes, you can individually override any of the settings adjusted by languageServerMode
. For example, you can re-enable indexing or Pytest support by explicitly setting those configurations in your settings.json
.
A: Light
mode is ideal for large projects, systems with limited resources, or when you require a lightweight editing experience. If you need comprehensive IntelliSense and code analysis across your entire workspace, default
mode is recommended.
A: If you experience performance issues, such as high memory or CPU usage, slow editor responses, or lag in IntelliSense features, trying light
mode may help. You can monitor system performance and adjust settings as needed.
For more information on Pylance settings and customization, refer to the Pylance Settings and Customization documentation.
This document was generated with the assistance of AI and has been reviewed by humans for accuracy and completeness.