6

LSP Pyright

 2 years ago
source link: https://emacs-lsp.github.io/lsp-pyright/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

lsp-pyright#

lsp-mode client leveraging Pyright language server

Quickstart#

(use-package lsp-pyright
  :ensure t
  :hook (python-mode . (lambda ()
                          (require 'lsp-pyright)
                          (lsp))))  ; or lsp-deferred

Configuration#

lsp-pyright supports the following configuration. Each configuration is described in detail in Pyright Settings.

  • pyright.disableLanguageServices via lsp-pyright-disable-language-services
  • pyright.disableOrganizeImports via lsp-pyright-disable-organize-imports
  • python.analysis.autoImportCompletions via lsp-pyright-auto-import-completions
  • python.analysis.useLibraryCodeForTypes via lsp-pyright-use-library-code-for-types
  • python.analysis.typeshedPaths via lsp-pyright-typeshed-paths
  • python.analysis.diagnosticMode via lsp-pyright-diagnostic-mode
  • python.analysis.typeCheckingMode via lsp-pyright-typechecking-mode
  • python.analysis.logLevel via lsp-pyright-log-level
  • python.analysis.autoSearchPaths via lsp-pyright-auto-search-paths
  • python.analysis.extraPaths via lsp-pyright-extra-paths
  • python.venvPath via lsp-pyright-venv-path

Projects can be further configured using pyrightconfig.json file. For further details please see Pyright Configuration.

Usage notes#

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

Last update: April 25, 2022

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK