3 <!-- markdownlint-disable no-inline-html -->
4 <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>
5 <a href="https://patreon.com/fannheyward"><img src="https://c5.patreon.com/external/logo/become_a_patron_button.png" alt="Patreon donate button" /></a>
6 <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>
8 [Pyright](https://github.com/microsoft/pyright) extension for coc.nvim
10 <!-- markdownlint-disable-next-line -->
11 <img width="603" alt="1" src="https://user-images.githubusercontent.com/345274/64470245-bda9a780-d172-11e9-9fda-48af0617a2ee.png">
15 `:CocInstall coc-pyright`
17 Note: Pyright may not work as expected if can't detect *project root* correctly, check [#521](https://github.com/fannheyward/coc-pyright/issues/521#issuecomment-858530052) and [Using workspaceFolders](https://github.com/neoclide/coc.nvim/wiki/Using-workspaceFolders#resolve-workspace-folder) in coc.nvim.
21 - `python.runLinting`: Run linting
22 - `python.sortImports`: Sort imports by `isort`
23 - `pyright.version`: Show the currently used Pyright version in `:messages`
24 - `pyright.organizeimports`: Organize imports by Pyright
25 - `pyright.restartserver`: This command forces the type checker to discard all of its cached type information and restart analysis. It is useful in cases where new type stubs or libraries have been installed.
26 - `pyright.createtypestub`: Creates Type Stubs with given module name, for example `:CocCommand pyright.createtypestub numpy`
30 These configurations are used by `coc-pyright`, you need to set them in your `coc-settings.json`.
32 | Configuration | Description | Default |
33 | ------------------------------------------- | ------------------------------------------------------------------- | ------------- |
34 | pyright.enable | Enable coc-pyright extension | true |
35 | python.analysis.autoImportCompletions | Determines whether pyright offers auto-import completions | true |
36 | python.analysis.autoSearchPaths | Automatically add common search paths like 'src' | true |
37 | python.analysis.diagnosticMode | Analyzes and reports errors for open only or all files in workspace | openFilesOnly |
38 | python.analysis.stubPath | Path to directory containing custom type stub files | typings |
39 | python.analysis.typeshedPaths | Paths to look for typeshed modules | [] |
40 | python.analysis.diagnosticSeverityOverrides | Override the severity levels for individual diagnostics | {} |
41 | python.analysis.typeCheckingMode | Defines the default rule set for type checking | basic |
42 | python.analysis.useLibraryCodeForTypes | Use library implementations to extract type information | true |
43 | python.pythonPath | Path to Python | python |
44 | python.venvPath | Path to folder with a list of Virtual Environments | "" |
45 | python.formatting.provider | Provider for formatting | autopep8 |
46 | python.formatting.blackPath | Custom path to black | black |
47 | python.formatting.blackArgs | Arguments passed to black | [] |
48 | python.formatting.blackdPath | Custom path to blackd | blackd |
49 | python.formatting.blackdHTTPURL | Custom blackd server url | "" |
50 | python.formatting.blackdHTTPHeaders | Custom blackd request headers | {} |
51 | python.formatting.yapfPath | Custom path to yapf | yapf |
52 | python.formatting.yapfArgs | Arguments passed to yapf | [] |
53 | python.formatting.autopep8Path | Custom path to autopep8 | autopep8 |
54 | python.formatting.autopep8Args | Arguments passed to autopep8 | [] |
55 | python.linting.enabled | Whether to lint Python files | true |
56 | python.linting.flake8Enabled | Whether to lint with flake8 | false |
57 | python.linting.banditEnabled | Whether to lint with bandit | false |
58 | python.linting.mypyEnabled | Whether to lint with mypy | false |
59 | python.linting.pytypeEnabled | Whether to lint with pytype | false |
60 | python.linting.pycodestyleEnabled | Whether to lint with pycodestyle | false |
61 | python.linting.prospectorEnabled | Whether to lint with prospector | false |
62 | python.linting.pydocstyleEnabled | Whether to lint with pydocstyleEnabled | false |
63 | python.linting.pylamaEnabled | Whether to lint with pylama | false |
64 | python.linting.pylintEnabled | Whether to lint with pylint | false |
65 | python.sortImports.path | Path to isort script, default using inner version | '' |
66 | python.sortImports.args | Arguments passed to isort | [] |
67 | pyright.server | Custom `pyright-langserver` path | '' |
68 | pyright.disableCompletion | Disables completion from Pyright, left other LSP features work | false |
69 | pyright.disableDiagnostics | Disable diagnostics from Pyright | false |
70 | pyright.completion.importSupport | Enable `python-import` completion source support | true |
71 | pyright.completion.snippetSupport | Enable completion snippets support | true |
72 | pyright.organizeimports.provider | Organize imports provider, `pyright` or `isort` | pyright |
76 Pyright supports [pyrightconfig.json](https://github.com/microsoft/pyright/blob/master/docs/configuration.md) that provide granular control over settings.
78 ## Python typing and stub files
80 To provide best experience, Pyright requires packages to be type annotated
81 and/or have stub files. The Python community is currently in a transition phase
82 where package authors are actively looking to provide that. Meanwhile, stub
83 files for well-known packages may also be obtained from 3rd party, for example:
85 - [Awesome Python Typing # stub-packages](https://github.com/typeddjango/awesome-python-typing#stub-packages)
86 - [typeshed](https://github.com/python/typeshed)
87 - [python-type-stubs](https://github.com/microsoft/python-type-stubs)
91 1. Create the following file:
96 2. Make it executable: `chmod +x $path`
97 3. Add the following to your `coc-settings.json`:
99 "python.pythonPath": "<PUT PATH HERE>"
101 4. Activate the environment before starting vim
103 This way python from your currently activated environment will be used
105 ## My Workflow with Pyright
107 1. create venv in project: `python3 -m venv .venv`
108 2. `source .venv/bin/activate`
109 3. install modules with pip and work with Pyright
118 > This extension is created by [create-coc-extension](https://github.com/fannheyward/create-coc-extension)