lsp-mode client leveraging Pyright language server
(use-package lsp-pyright
:ensure t
:hook (python-mode . (lambda ()
(require 'lsp-pyright)
(lsp)))) ; or lsp-deferred
lsp-pyright
supports the following configuration. Each configuration is described in detail in
Pyright Settings.
pyright.disableLanguageServices
vialsp-pyright-disable-language-services
pyright.disableOrganizeImports
vialsp-pyright-disable-organize-imports
python.analysis.autoImportCompletions
vialsp-pyright-auto-import-completions
python.analysis.useLibraryCodeForTypes
vialsp-pyright-use-library-code-for-types
python.analysis.typeshedPaths
vialsp-pyright-typeshed-paths
python.analysis.diagnosticMode
vialsp-pyright-diagnostic-mode
python.analysis.typeCheckingMode
vialsp-pyright-typechecking-mode
python.analysis.logLevel
vialsp-pyright-log-level
python.analysis.autoSearchPaths
vialsp-pyright-auto-search-paths
python.analysis.extraPaths
vialsp-pyright-extra-paths
python.venvPath
vialsp-pyright-venv-path
Projects can be further configured using pyrightconfig.json
file. For further details please see
Pyright Configuration.
lsp-pyright
will try its best to select the correct version of the
python executable to use. It will do so by iteratively executing
different search functions, going from most precise to most
general.
The list and order of the list can be modified by customizing
lsp-pyright-python-search-functions
. By default the order is:
- Look for a parent directory with a virtual-environment named
.venv
orvenv
vialsp-pyright--locate-python-venv
. - Look for a python executable on your PATH via
lsp-pyright--locate-python-python
.
Pyright includes a recent copy of the Python stdlib type stubs. To add type stubs for additional
libraries, customize lsp-pyright-stub-path
, or place the appropriate type stubs in typings
subdirectory of your project (this is the default stub path). Note that without stubs but with
lsp-pyright-use-library-code-for-types
non-nil, you may see type checking errors, particularly
for complex libraries such as Pandas.
Example setup to get typechecking working properly for Pandas:
git clone https://github.com/microsoft/python-type-stubs $HOME/src
(setq lsp-pyright-use-library-code-for-types t) ;; set this to nil if getting too many false positive type errors
(setq lsp-pyright-stub-path (concat (getenv "HOME") "/src/python-type-stubs")) ;; example