Home

Awesome

coc-pyright

<!-- markdownlint-disable no-inline-html -->

<a href="https://github.com/sponsors/fannheyward"><img src="https://user-images.githubusercontent.com/345274/133218454-014a4101-b36a-48c6-a1f6-342881974938.png" alt="GitHub Sponsors" /></a> <a href="https://patreon.com/fannheyward"><img src="https://c5.patreon.com/external/logo/become_a_patron_button.png" alt="Patreon donate button" /></a> <a href="https://paypal.me/fannheyward"><img src="https://user-images.githubusercontent.com/345274/104303610-41149f00-5505-11eb-88b2-5a95c53187b4.png" alt="PayPal donate button" /></a>

Pyright extension for coc.nvim, with additional features:

<!-- markdownlint-disable-next-line --> <img width="1173" alt="image" src="https://github.com/fannheyward/coc-pyright/assets/345274/eb1230ec-26d0-4c2f-9b13-d6462e064559">

Install

:CocInstall coc-pyright

Note: Pyright may not work as expected if can't detect project root correctly, check #521 and Using workspaceFolders in coc.nvim.

Commands

Configurations

These configurations are used by coc-pyright, you need to set them in your coc-settings.json.

ConfigurationDescriptionDefault
pyright.enableEnable coc-pyright extensiontrue
python.analysis.autoImportCompletionsDetermines whether pyright offers auto-import completionstrue
python.analysis.autoSearchPathsAutomatically add common search paths like 'src'true
python.analysis.diagnosticModeAnalyzes and reports errors for open only or all files in workspaceopenFilesOnly
python.analysis.stubPathPath to directory containing custom type stub filestypings
python.analysis.typeshedPathsPaths to look for typeshed modules[]
python.analysis.diagnosticSeverityOverridesOverride the severity levels for individual diagnostics{}
python.analysis.typeCheckingModeDefines the default rule set for type checkingbasic
python.analysis.useLibraryCodeForTypesUse library implementations to extract type informationtrue
python.pythonPathPath to Pythonpython
python.venvPathPath to folder with a list of Virtual Environments""
python.formatting.providerProvider for formattingautopep8
python.formatting.blackPathCustom path to blackblack
python.formatting.blackArgsArguments passed to black[]
python.formatting.darkerPathCustom path to darkerdarker
python.formatting.darkerArgsArguments passed to darker[]
python.formatting.pyinkPathCustom path to pyinkpyink
python.formatting.pyinkArgsArguments passed to pyink[]
python.formatting.blackdPathCustom path to blackdblackd
python.formatting.blackdHTTPURLCustom blackd server url""
python.formatting.blackdHTTPHeadersCustom blackd request headers{}
python.formatting.yapfPathCustom path to yapfyapf
python.formatting.yapfArgsArguments passed to yapf[]
python.formatting.autopep8PathCustom path to autopep8autopep8
python.formatting.autopep8ArgsArguments passed to autopep8[]
python.linting.enabledWhether to lint Python files with external linterstrue
python.linting.flake8EnabledWhether to lint with flake8false
python.linting.banditEnabledWhether to lint with banditfalse
python.linting.mypyEnabledWhether to lint with mypyfalse
python.linting.ruffEnabledWhether to lint with rufffalse
python.linting.pytypeEnabledWhether to lint with pytypefalse
python.linting.pycodestyleEnabledWhether to lint with pycodestylefalse
python.linting.prospectorEnabledWhether to lint with prospectorfalse
python.linting.pydocstyleEnabledWhether to lint with pydocstylefalse
python.linting.pylamaEnabledWhether to lint with pylamafalse
python.linting.pylintEnabledWhether to lint with pylintfalse
python.linting.pyflakesEnabledWhether to lint with pyflakesfalse
python.sortImports.pathPath to isort script, default using inner version''
python.sortImports.argsArguments passed to isort[]
pyright.serverCustom pyright-langserver path''
pyright.disableCompletionDisables completion from Pyrightfalse
pyright.disableDiagnosticsDisable diagnostics from Pyrightfalse
pyright.disableDocumentationDisables hover documentation from Pyrightfalse
pyright.disableProgressNotificationsDisable the initialization and workdone progress notificationsfalse
pyright.completion.importSupportEnable python-import completion source supporttrue
pyright.completion.snippetSupportEnable completion snippets supporttrue
pyright.organizeimports.providerOrganize imports provider, pyright, ruff or isortpyright
pyright.inlayHints.functionReturnTypesEnable inlay hints for function return typestrue
pyright.inlayHints.variableTypesEnable inlay hints for variable typestrue
pyright.inlayHints.parameterTypesEnable inlay hints for parameter typestrue
pyright.testing.providerProvider for testing, supports unittest and pytestunittest
pyright.testing.unittestArgsArguments passed to unittest[]
pyright.testing.pytestArgsArguments passed to pytest[]

Additional configuration options can be found in package.json.

pyrightconfig.json

Pyright supports pyrightconfig.json that provide granular control over settings.

Python typing and stub files

To provide best experience, Pyright requires packages to be type annotated and/or have stub files. The Python community is currently in a transition phase where package authors are actively looking to provide that. Meanwhile, stub files for well-known packages may also be obtained from 3rd party, for example:

Conda setup

  1. Create the following file:

    #!/bin/bash
    python "$@"
    
  2. Make it executable: chmod +x $path

  3. Set python.pythonPath in your coc-settings.json: "python.pythonPath": "<PUT PATH HERE>"

  4. Activate the environment before starting vim

This way python from your currently activated environment will be used

My Workflow with Pyright

  1. create venv in project: python3 -m venv .venv
  2. source .venv/bin/activate
  3. install modules with pip and work with Pyright
  4. deactivate

License

MIT


This extension is built with create-coc-extension