Git Product home page Git Product logo

coc-pyright's Introduction

coc-pyright

GitHub Sponsors Patreon donate button PayPal donate button

Pyright extension for coc.nvim, with additional features:

  • semanticTokens highlighting!
  • inlayHints supports
  • codeActions to add imports, ignore typing check, run tests and more
  • linting with bandit, flake8, mypy, ruff, prospector, pycodestyle, pydocstyle, pyflakes, pylama, pylint, pytype
  • formatting with ruff, yapf, black, autopep8, darker, blackd, pyink
  • testing with unittest or pytest, supports codeLens
  • sort imports with ruff, isort and pyright
  • extract method and variables with rope
image

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

  • python.runLinting: Run linting
  • python.sortImports: Sort imports by isort or ruff
  • pyright.version: Show the currently used Pyright version
  • pyright.organizeimports: Organize imports by Pyright
  • 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.
  • pyright.createtypestub: Creates Type Stubs with given module name, for example :CocCommand pyright.createtypestub numpy
  • pyright.fileTest: Run test for current test file
  • pyright.singleTest: Run test for single nearest test

Configurations

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

Configuration Description Default
pyright.enable Enable coc-pyright extension true
python.analysis.autoImportCompletions Determines whether pyright offers auto-import completions true
python.analysis.autoSearchPaths Automatically add common search paths like 'src' true
python.analysis.diagnosticMode Analyzes and reports errors for open only or all files in workspace openFilesOnly
python.analysis.stubPath Path to directory containing custom type stub files typings
python.analysis.typeshedPaths Paths to look for typeshed modules []
python.analysis.diagnosticSeverityOverrides Override the severity levels for individual diagnostics {}
python.analysis.typeCheckingMode Defines the default rule set for type checking basic
python.analysis.useLibraryCodeForTypes Use library implementations to extract type information true
python.pythonPath Path to Python python
python.venvPath Path to folder with a list of Virtual Environments ""
python.formatting.provider Provider for formatting autopep8
python.formatting.blackPath Custom path to black black
python.formatting.blackArgs Arguments passed to black []
python.formatting.darkerPath Custom path to darker darker
python.formatting.darkerArgs Arguments passed to darker []
python.formatting.pyinkPath Custom path to pyink pyink
python.formatting.pyinkArgs Arguments passed to pyink []
python.formatting.blackdPath Custom path to blackd blackd
python.formatting.blackdHTTPURL Custom blackd server url ""
python.formatting.blackdHTTPHeaders Custom blackd request headers {}
python.formatting.yapfPath Custom path to yapf yapf
python.formatting.yapfArgs Arguments passed to yapf []
python.formatting.autopep8Path Custom path to autopep8 autopep8
python.formatting.autopep8Args Arguments passed to autopep8 []
python.linting.enabled Whether to lint Python files with external linters true
python.linting.flake8Enabled Whether to lint with flake8 false
python.linting.banditEnabled Whether to lint with bandit false
python.linting.mypyEnabled Whether to lint with mypy false
python.linting.ruffEnabled Whether to lint with ruff false
python.linting.pytypeEnabled Whether to lint with pytype false
python.linting.pycodestyleEnabled Whether to lint with pycodestyle false
python.linting.prospectorEnabled Whether to lint with prospector false
python.linting.pydocstyleEnabled Whether to lint with pydocstyle false
python.linting.pylamaEnabled Whether to lint with pylama false
python.linting.pylintEnabled Whether to lint with pylint false
python.linting.pyflakesEnabled Whether to lint with pyflakes false
python.sortImports.path Path to isort script, default using inner version ''
python.sortImports.args Arguments passed to isort []
pyright.server Custom pyright-langserver path ''
pyright.disableCompletion Disables completion from Pyright false
pyright.disableDiagnostics Disable diagnostics from Pyright false
pyright.disableDocumentation Disables hover documentation from Pyright false
pyright.disableProgressNotifications Disable the initialization and workdone progress notifications false
pyright.completion.importSupport Enable python-import completion source support true
pyright.completion.snippetSupport Enable completion snippets support true
pyright.organizeimports.provider Organize imports provider, pyright, ruff or isort pyright
pyright.inlayHints.functionReturnTypes Enable inlay hints for function return types true
pyright.inlayHints.variableTypes Enable inlay hints for variable types true
pyright.inlayHints.parameterTypes Enable inlay hints for parameter types true
pyright.testing.provider Provider for testing, supports unittest and pytest unittest
pyright.testing.unittestArgs Arguments passed to unittest []
pyright.testing.pytestArgs Arguments 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

coc-pyright's People

Contributors

bvolkmer avatar d-mitrofanov-v avatar dependabot-preview[bot] avatar dependabot[bot] avatar dob9601 avatar extremepayne avatar fannheyward avatar gentiksolm avatar gera2ld avatar lambdalisue avatar lithammer avatar oblitum avatar onenutw0nder avatar rizhiy avatar strayer avatar tejasvi avatar timsu92 avatar tonyseek avatar trygveaa avatar vad avatar yaegassy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

coc-pyright's Issues

Language server fails to initialize

I'm trying to use coc-pyright but after installing and opening a python file I get the following:
[coc.nvim] The "pyright" server crashed 5 times in the last 3 minutes. The server will not be restarted.

The output is the following message repeated several times:

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'worker_threads'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.5013 (/home/marco/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:1:561)
    at s (/home/marco/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:1:687)
    at Object.8863 (/home/marco/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-internal.js:1:801994)
    at s (/home/marco/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:1:687)
    at Object.5822 (/home/marco/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:1:46)
    at s (/home/marco/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:1:687)

CocInfo:

vim version: NVIM v0.5.0-823-g42ffa2d62
node version: v10.19.0
coc.nvim version: 0.0.79-bd91ae4254
coc.nvim directory: /home/marco/.config/nvim/plugged/coc.nvim
term: xterm-256color
platform: linux

Am I missing something?

problem with setting the interpreter

python.setInterpreter doesn't work for me, heres the problem:
if I have python.pythonPath in my coc config, I can't change the intrepreter when I want to use a virtual environment,
to solve this, I removed python.pythonPath from coc config and now I can use my venv interpreter, but now I can't use pyright outside of my project, cause I removed python.pythonPath from coc config and now pyright has no interpreters to work with,

so I put it back in the coc config file, now it works fine out of projects, but in the projects? it doesn't know my imports ( cause they are installed in a venv ) and python.setInterpreter doesn't work AT ALL.

I'll try to record my screen to show it...

Built-in docstrings

Docstrings for third-party libraries and custom functions work. Would it be possible to reallow builtin functions (e.g. print) to also display docstrings?

See here for more information: microsoft/pylance-release#49

EDIT: Whoops, I meant to raise this issue in the pyright repository. Please close if it's not relevant.

"sqrt" is not a known member of module (numpy)

When running the command-line pyright on

import numpy

numpy.sqrt(5.0)

I correctly get

No configuration file found.
stubPath /tmp/typings is not a valid directory.
Assuming Python platform Linux
Searching for source files
Found 1 source file
0 errors, 0 warnings, 0 infos
Completed in 0.635sec

When using coc-pyright, I get

[Pyright (reportGeneralTypeIssues)] [E] "sqrt" is not a known member of module

A bug?

python.venvPath config setting does not expand variables

I'm migrating from coc-python, and I have this in my global config file

  "python.venvPath":"~/.virtualenvs",

Previously this worked, but now I see the following message in the pyright output:

[Error  - 12:17:32] venvPath /home/ash/code/airflow/airflow/~/.virtualenvs is not a valid directory.

I also tried with $HOME, neither worked.

Please could one of these expansion mechanisms work before the config is passed on to pyright?

could not be resolved if use pyenv local

I use pyenv for manage virtualenv of python, but if use pyenv local(.python-version file in local dir) in coc-pyright, raise reportMissingImports error on import something.
image

pyenv shell is working. PYENV_VERSION environment variable can be accepted.

Enable black and sort on save doesn't work

with the following configuration:

{
  "coc.preferences.formatOnSaveFiletypes": [
    "css",
    "markdown",
    "javascript",
    "graphql",
    "html",
    "yaml",
    "json",
    "python"
  ],
  // python config
  "coc.source.vimtex.enable": true,
  "coc.preferences.extensionUpdateCheck": "daily",
  "python.pythonPath": "",
  "pyright.disableLanguageServices": false,
  "suggest.enablePreview": true,
  "diagnostic.virtualText": true,
  "diagnostic.virtualTextCurrentLineOnly": false,
  "python.formatting.provider": "black",
  "codeLens.enable": true,
  "python.linting.enabled": true,
  "python.linting.pylintArgs": [
    "--load-plugins",
    "--rcfile",
    "~/.pylintrc",
    "-d",
    "C0411"
  ],
  "python.formatting.blackPath": "",
  "python.venvPath": "",
  "python.linting.pylintUseMinimalCheckers": false,
  "python.linting.pylintPath": "pylint",
  "snippets.ultisnips.directories": [
    "UltiSnips",
    "~/.config/nvim/utils/snips"
  ]
}

The black and sort on save are not working. Any suggestions?

Formatting not work with relative PATH

Hi, @fannheyward @Maswor

I also tried the format feature ported from coc-python or vscode-python.

Relative PATH was also possible when setting python.formatting.blackPath in "coc-python".

In "coc-pyright", you had to specify it in the absolute PATH.

If you set up "coc-pyright" with a relative PATH, it seems to show only the echo message, not the actual formatting.

Relative PATH (NG)

{
  // ...snip
  "python.formatting.blackPath": "~/.local/bin/black",
  // ...snip
}

DEMO

01_coc-pyright-black-path-relative-path

Absolute PATH (OK)

{
  // ...snip
  "python.formatting.blackPath": "/Users/yaegassy/.local/bin/black",
  // ...snip
}

DEMO

02_coc-pyright-black-path-absolute-path

Originally posted by @yaegassy in #81 (comment)

"Rename" does not work with coc-python + coc-pyright

Describe the bug

I use coc-python + coc-pyright.

"Rename" doesn't work if coc-pyright is installed.

An error message [coc.nvim] Invalid position for rename is displayed.

"Rename" works when coc-pyright is uninstalled.

CocInfo versions

vim version: NVIM v0.5.0-340-gd3a9d75c0
node version: v12.13.1
coc.nvim version: 0.0.74
term: iTerm.app
platform: darwin

coc-settings.json

  ...snip
  "python.jediEnabled": false,
  ...snip
  "pyright.disableLanguageServices": true,
  "pyright.openFilesOnly": true,
  ...snip

Demo (Animation GIF)

coc-pyright-rename-issue-1200

pyright can not work, using :CocInfo exerts an error

versions

vim version: NVIM v0.5.0-610-g326b87feb
node version: v14.5.0
coc.nvim version: 0.0.78-0ff42027ff
coc.nvim directory: /home/kino/.cache/dein/repos/github.com/neoclide/coc.nvim_release
term: xterm-256color
platform: linux

Output channel: Pyright

[Info - 8:45:28 AM] Pyright language server 1.1.60 starting
[Info - 8:45:28 AM] Server root directory: /home/kino/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/
[Error - 8:45:28 AM] stubPath typings is not a valid directory.

Change root pattern

Thank you for the plugin. I am wondering if there is a way to change the root pattern? Or at least a way to look at what the root pattern is?

Thanks again.

Import "test" could not be resolved

coc-pyright is unable to resolve imports when importing a local file, such as

# main.py
from test import *

(both main.py and test.py are in the same directory)

coc-python -> coc-pyright

Background

  • coc-python forks from vscode-python, provides Python supports with Jedi/MSPL for code completions, ctags for workspaceSymbols, Black/X for code formatting, pylint/X for code linting, and more
  • MSPL will be deprecated instead of Pylance.
  • Pylance is powered by Pyright, static type checker for Python, with some closed-source IntelliCode functions.
  • Pyright has LSP supports, but lacks some feature, for example code formatting.

I've ported some features from vscode-python/coc-python to coc-pyright:

  • refactor with rope
  • sort imports with isort
  • format with black/blackd/yapf/autopep8
  • lint with flake8/mypy/pycodestyle/prospector/pydocstyle/pylama/pylint/bandit, and Pytype

Commands

coc-python coc-pyright Will Support?
python.startREPL - No
python.createTerminal - No
python.execInTerminal - No
python.buildWorkspaceSymbols - No
python.upgradePythonLanguageServer - No
python.viewOutput - No
python.goToPythonObject - No
python.setLinter - No
python.enableLinting - No
python.setInterpreter - No #99
python.runLinting python.runLinting
python.sortImports python.sortImports
- pyright.restartserver
- pyright.createtypestub

Configurations

coc-python coc-pyright Will support?
python.autoComplete.* - No
python.jedi* - No
python.autoUpdateLanguageServer - No
python.disableInstallationCheck - No
python.trace.server - No
python.globalModuleInstallation - No
python.analysis.downloadChannel - No
python.analysis.diagnosticEnabled - No
python.analysis.diagnosticPublishDelay - No
python.analysis.errors - No
python.analysis.warnings - No
python.analysis.information - No
python.analysis.disabled - No
python.analysis.symbolsHierarchyDepthLimit - No
python.condaPath - No
python.pipenvPath - No
python.poetryPath - No
python.venvFolders - No
python.workspaceSymbols.* - No
python.terminal.* - No
python.venvPath python.venvPath
python.pythonPath python.pythonPath
python.formatting.* python.formatting.*
- python.formatting.blackdPath
- python.formatting.blackdHTTPURL
python.sortImports.* python.sortImports.*
python.linting.* python.linting.*
- python.linting.pytypeEnabled
- python.linting.pytypePath
- python.linting.pytypeArgs
python.analysis.typeshedPaths python.analysis.typeshedPaths
python.analysis.openFilesOnly python.analysis.diagnosticMode
python.analysis.logLevel python.analysis.logLevel
- python.analysis.extraPaths
- python.analysis.typeshedPaths
- python.analysis.autoImportCompletions
- python.analysis.autoSearchPaths
- python.analysis.stubPath
- python.analysis.diagnosticSeverityOverrides
- python.analysis.typeCheckingMode
- python.analysis.useLibraryCodeForTypes
- pyright.disableCompletion
- pyright.disableLanguageServices
- pyright.disableOrganizeImports

Coc-pyright removes sourcery's quickfixes

Sourcery is an AI tool that refactors code link. It adds items to :CocFix, when it finds any ways to improve the code. When coc-pyright is installed, it somehow overwrites those fixes.

e.g.
image
When coc-pyright is not installed, :CocFix changes dict() to {}. With coc-pyright installed, nvim prints [coc.nvim] No quickfix action available.

Code from the image
class choises_printer:
    def __init__(self):
        self.choise = dict()

    def set_choise(l: int, i: int):
        self.choise[l] = i
Please tell me if you need any additional information.

pyright.disableLanguageServices seems to get ignored

Hi there,

I use coc-python for completion and coc-pyright for linting. I disabled completion for coc-pyright to circumvent duplicate completion items. However, pyright.disableLanguageServices seems to get ignored.

I tested multiple versions, and it breaks at 1.0.82. Version 1.0.81 shows no duplicates and 1.0.82 does.

Cheers,
Hans

Fails to resolve file from local directory

Pyright fails to resolve file from local directory.
I tried to install pyright in vscode and it does not complain the same way. I wonder if there is a place somewhere to set '.' as path as well or something similar?

2020-11-23_091002_240684614

coc-pyright showing a wrong error

I was starting to use the extension today and noticed it not finding multiple methods of BluetoothSocket (connect, send, recv, close), it does show bind, accept and a few more.

Screen_2020-12-17_22:25:30

The VSCode-Version does not show the error in the same line.
Screen_2020-12-17_22:25:39
Did I do something wrong or is this a bug?

Crash on startup

When I try to use coc-pyright (with our without coc-python) I get the following eerror:

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'worker_threads'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at eval (webpack://pyright-server/external_%22worker_threads%22?:1:18)
    at Object.worker_threads (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:3803:1)
    at __webpack_require__ (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:3826:42)
    at eval (webpack://pyright-server/./src/server.ts?:19:26)
    at Object../src/server.ts (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:2295:1)
    at __webpack_require__ (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:3826:42)
[Info  - 11:59:00 AM] Connection to server got closed. Server will restart.
internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'worker_threads'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at eval (webpack://pyright-server/external_%22worker_threads%22?:1:18)
    at Object.worker_threads (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:3803:1)
    at __webpack_require__ (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:3826:42)
    at eval (webpack://pyright-server/./src/server.ts?:19:26)
    at Object../src/server.ts (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:2295:1)
    at __webpack_require__ (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:3826:42)
[Info  - 11:59:00 AM] Connection to server got closed. Server will restart.
internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'worker_threads'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at eval (webpack://pyright-server/external_%22worker_threads%22?:1:18)
    at Object.worker_threads (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:3803:1)
    at __webpack_require__ (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:3826:42)
    at eval (webpack://pyright-server/./src/server.ts?:19:26)
    at Object../src/server.ts (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:2295:1)
    at __webpack_require__ (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:3826:42)
[Info  - 11:59:00 AM] Connection to server got closed. Server will restart.
internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'worker_threads'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at eval (webpack://pyright-server/external_%22worker_threads%22?:1:18)
    at Object.worker_threads (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:3803:1)
    at __webpack_require__ (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:3826:42)
    at eval (webpack://pyright-server/./src/server.ts?:19:26)
    at Object../src/server.ts (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:2295:1)
    at __webpack_require__ (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:3826:42)
[Info  - 11:59:00 AM] Connection to server got closed. Server will restart.
internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'worker_threads'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at eval (webpack://pyright-server/external_%22worker_threads%22?:1:18)
    at Object.worker_threads (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:3803:1)
    at __webpack_require__ (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:3826:42)
    at eval (webpack://pyright-server/./src/server.ts?:19:26)
    at Object../src/server.ts (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:2295:1)
    at __webpack_require__ (/Users/david.maia/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/pyright-langserver.js:3826:42)
[Error  - 11:59:00 AM] Connection to server got closed. Server will not be restarted.

Python extraPaths

Hi!

Would it be possible to be able to set the python.analysis.extraPaths option, it seems to be available in pyright? The option is also available in coc-python, but is listed under autoComplete instead of analysis.

This is useful when your projects are not on the pythonpath per se.

2 Questions

  1. So I'm considering switching to this Python extension from coc-python. What are the main benefits?
  2. The extension seems to be working - I get some useful diagnostic messages and the completion is a bit slow but not much slower then coc-python. I do get a lot of could not import '<module>' in CocInfo. What does that mean?

Example for part of the log:

Could not import 'PIL' in file '/var/src/beets/beets/util/artresizer.py'
  Looking for typeshed stdlib path
  Attempting to resolve using root path '/home/doron/.config/coc/extensions/node_modules/coc-pyright/typeshed-fallback/stdlib/3.7'
  Could not find directory '/home/doron/.config/coc/extensions/node_modules/coc-pyright/typeshed-fallback/stdlib/3.7/PIL'
  Did not find file '/home/doron/.config/coc/extensions/node_modules/coc-pyright/typeshed-fallback/stdlib/3.7/PIL.pyi', '/home/doron/.config/coc/extensions/node_modules/coc-pyright/typeshed-fallback/stdlib/3.7/PIL.py' or '/home/doron/.config/coc/extensions/node_modules/coc-pyright/typeshed-fallback/stdlib/3.7/PIL.pyd'
  Attempting to resolve using root path '/home/doron/.config/coc/extensions/node_modules/coc-pyright/typeshed-fallback/stdlib/3.6'
  Could not find directory '/home/doron/.config/coc/extensions/node_modules/coc-pyright/typeshed-fallback/stdlib/3.6/PIL'
  Did not find file '/home/doron/.config/coc/extensions/node_modules/coc-pyright/typeshed-fallback/stdlib/3.6/PIL.pyi', '/home/doron/.config/coc/extensions/node_modules/coc-pyright/typeshed-fallback/stdlib/3.6/PIL.py' or '/home/doron/.config/coc/extensions/node_modules/coc-pyright/typeshed-fallback/stdlib/3.6/PIL.pyd'
  Attempting to resolve using root path '/home/doron/.config/coc/extensions/node_modules/coc-pyright/typeshed-fallback/stdlib/3'
  Could not find directory '/home/doron/.config/coc/extensions/node_modules/coc-pyright/typeshed-fallback/stdlib/3/PIL'
  Did not find file '/home/doron/.config/coc/extensions/node_modules/coc-pyright/typeshed-fallback/stdlib/3/PIL.pyi', '/home/doron/.config/coc/extensions/node_modules/coc-pyright/typeshed-fallback/stdlib/3/PIL.py' or '/home/doron/.config/coc/extensions/node_modules/coc-pyright/typeshed-fallback/stdlib/3/PIL.pyd'

Handling 'unused parameter' hints

Pyright flags unused function parameters with a hint.

Screen Shot 2020-10-24 at 12 11 12 PM

That is often helpful, but when you're trying to satisfy some library's API, you may want to include placeholders for parameters even if a function or method doesn't actually use them. An unused argument warning can be silenced by naming a parameter _, but that only works for one parameter. Names can be dundered (like __name__), but that feels like a hack, and doesn't work for keyword parameters. You could also use *arg and **kwargs, but is a bit less clear that having placeholders.

According to this, the Pyright language server tags unused parameter hints in some way, and the LSP client can tell Pyright that it doesn't support this tag to prevent Pyright from sending these hints. Possibly coc-pyright could provide an option to disable unused argument hints.

关于 Python 虚拟环境以及 PYTHONPATH 的问题

我发现我项目中写了某写模块,必须手动export PYTHONPATH到那个包的地址才行,否则import 就会提示错误。
而且还有一个问题,虚拟环境可以配置相对地址嘛。一般都是项目根路径下的某个文件夹

workspaceSymbols

Hi!

Pyright added support for workspaceSymbols (e.g. CocList symbols), though only "outline" is available from within coc. Otherwise I find that coc-pyright already quite suitably can replace coc-python, especially since the LSP starts a lot faster :)

Many thanks for your work on the plugin and consideration!

`python.analysis.extraPaths` setting not working

CocConfig:

{
"python.autoComplete.extraPaths": [
    "/home/thib/catkin_ws/devel/lib/python3/dist-packages",
    "/home/thib/main/svpy",
  ],
"python.analysis.extraPaths": [
    "/home/thib/catkin_ws/devel/lib/python3/dist-packages",
    "/home/thib/main/svpy",
  ]
}

When importing modules from outside the working project, the following import error shows up:

from sv_msgs.msg import PickupZoneArray, PickupZone
                                          [Pyright (reportGeneralTypeIssues)] [E] "PickupZoneArray" is unknown import symbol    

When importing modules from within the working project, the following error import shows up:

from pymongo.database import Database
                   [Pyright (reportMissingImports)] [E] Import "pymongo.database" could not be resolved

coc-python works without issue with the right python.autoComplete.extraPaths. But somehow coc-pyright ignore those extra paths.

venv black is not used for formatting

It seems that even though black is installed into the relevant virtualenv, coc-pyright is not utilizing it. There doesn't seem to be an error, instead when the formatter runs nothing appears to happen. However if I run the formatter directly, i.e. in the activated virtualenv, then it works as expected.

"python.linting.enabled": false Do not work

I just use pyright's goto definition and goto reference, so I try to set "python.linting.enabled": false in coc-settings.json, but this setting do not work
{ "python.linting.enabled": false, }

coc-pyright doesn't work

Steps:

  • install neovim in a new deepin linux(without doing any other things), and install the lastest neovim(version 0.4.4) to my linux.
  • install node.js(version 14.8.0) to my linux.
  • download vim-plug
  • edit ~/.config/nvim/init.vim:
call plug#begin('~/.config/nvim/plugged')
    Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
  • type PlugInstall and CocInstall coc-pyright.
  • and try nvim /tmp/test.py,pyright still not work.

Originally posted by @DedSecer in #82 (comment)

Don't minimize packaged plugin.

Is there need for using minimization webpack feature?

It is not used in browser, and it's hard to debug it with minimization enabled.

how to get pyright info on lightline?

I use conda as my python env manager...and I want know which conda env I used now...So I want to know how I set coc-pyright that current python env can be show on the lightline... call coc#status() seems no thing happen...

pyright reportMissingImports and setting project root directory

Hi, as I mentioned in this issue, the pyright is producing reportMissingImports warning when I am trying to import anything from my own django apps.
I believe the issue is related to where my project root is set.
below is my working directory.

project  (this is what pyright thinks the cwd is)
| -- django_project   (this should be the cwd)
|    | -- manage.py
|    | -- Pipfile
|    | -- my_app
|    | --  ....rest of files and folders
|
|-- .git
|-- ... rest of files and folders

The lsp should think of the django_project as the root of working directory but instead thinking project as the working directory since the .git lives there. Therefore, when I try to use the auto import feature, it imports as from django_project.my_app.models import .....

I tried to set autocmd FileType python let b:coc_root_patterns = ["Pipfile"] on my nvim config file to override the working directory to be where the Pipfile is, and it works for coc-explorer but coc-pyright still does not work properly.

Is there any way to set cwd correctly to remove the warnings?

Thank you for your help in advance, and happy holidays!

Code formating

coc-pyright at the moment doesn't support formatting. From what I understand, pyright itself doesn't support formatting, but pylance does using vscode-python. Maybe you can take a look and see if it's possible to implement the functionality in coc-pyright. Thank you!

Separate virtualenv for nvim + coc-pyright and project.

I want to use two different virtualenvs, one for pyright utils like formatting, linting etc. and different for each project, so i in init.vim i set let g:python3_host_prog = '/home/user/.virtualenvs/nvim/bin/python' as base env named nvim, activate it, then add a pyrightconfig.json with {"venvPath": "/home/user/.virtualenvs", "venv": "proj-venv"}. When open project files pylint shows import errors on third party libs, but all pyright functionality works. If mix both virtualenvs and install all project requirements on nvim virtualenv the problem is solved, but it's not a clean solution.

No code action available when calling :CocAction

Whenever I call :CocAction, I get told that there are no code actions available - not even general ones such as sorting imports or formatting. Is this intended? I've tried reinstalling several times but with no change. I'm in the process of switching from coc-python to coc-pyright - so far I've found it to be great, aside from this

doc comments have extra new lines

I have the following function (which is simply from the "default" coc config)

function! s:show_documentation()
  if (index(['vim','help'], &filetype) >= 0)
    execute 'h '.expand('<cword>')
  elseif (coc#rpc#ready())
    call CocActionAsync('doHover')
  else
    execute '!' . &keywordprg . " " . expand('<cword>')
  endif
endfunction

I have noticed that doc comments which are multiple lines include extra new lines when displayed with this function.
Take this multi-line doc comment for example:

image

when using the function, I see:
image

As you can see, it is making newlines to make sure the doc stays within the bounds of the popup, but also including the new lines from the doc comment itself, resulting in weird breaks in the comment.

Apologies if this is not the plugin's fault but instead coc, vim, pyright, etc.

Thanks for the extension!

reportUnusedVariable is enabled by default and can not be disabled

This plugin marks unused variables, hovewer, reportUnusedVariable is disabled by default.

Like in this example:

def test(param):
    pass

image

i tried to disable it by adding this to CocConfig:

  "python.analysis.diagnosticSeverityOverrides": {
    "reportUnusedVariable": "none"
  },

But it does not works.

Does this looks like plugin problem, or maybe i should create issue in pyright repo?

Signature help fails on method defined below current line

class Test:
    def method1(self, param1):
        pass

    def method2(self, param1):
        pass

If you write self.method2( in method1 it will show autocomplete up until the parenthesis, but the signature help won't show up and this shows in CocOpenLog:
2020-12-07T20:53:48.491 WARN (pid:51074) [Handler] - signature help provider not found!

However if you go to method2 and write self.method1( the signature help works just fine, and in vscode with pylance both cases work (which I guess is using the same pyright backend for this).

CocCommand workspace.showOutput - coc-pyright-linting doesn't show any logs

My :CocConfig:

{
    // Change all location jump, like jump to definition, in new tab.
    // From https://github.com/neoclide/coc.nvim/issues/318#issuecomment-452488348
    "coc.preferences.jumpCommand": "tab drop",

    // coc-pyright
    "python.linting.banditEnabled": true,
    "python.linting.flake8Enabled": true,
    "python.linting.mypyEnabled": true,
    "python.linting.pydocstyleEnabled": true,
    "python.linting.pylintEnabled": true
}

:CocCommand workspace.showOutput - coc-pyright-linting opens an empty vertical split window. It should show active linter:xxx logs.

I have all the linters installed in my system with pipenv, and I execute pipenv shell before using neovim.

workspaceSymbols very slow

I work with a large code base (apache/airflow) and workspaceSymbols :CocList -I symbols is very slow, and I pay that cost each time I have to use it.

I'm not sure if this is issue belongs here or in pyright itself, but I was wondering if there is some option so this could be cached?

coc-python signatureHelp stops working

I've configured coc-pyright with:

  call coc#config('pyright', {
  \   'disableLanguageServices': v:true
  \ })

Because I'm trying to use it with coc-python, but now I don't get signatureHelp from either place.

pdData.head()出错

pdData.head()出错 Cannot access member 'head' for type 'TextFileReader'
但是在命令行下运行 python 3.8 后,逐条语句输入就没有错误。

Creating stub files

Trying to create a stubs file for pandas:

:CocCommand pyright.createtypestub pandas

[coc.nvim] An error occurred when creating type stub for 'pandas': No typings path was specified
[coc.nvim] error: UnhandledRejection: Request workspace/executeCommand failed unexpectedly without providing any details.
Error: Request workspace/executeCommand failed unexpectedly without providing any details.
at handleResponse (/home/felipemarcelino/.config/nvim/plugged/coc.nvim/build/index.js:15819:48)
at processMessageQueue (/home/felipemarcelino/.config/nvim/plugged/coc.nvim/build/index.js:15646:1
7)
at Immediate. (/home/felipemarcelino/.config/nvim/plugged/coc.nvim/build/index.js:15630
:13)
at processImmediate (internal/timers.js:445:21)

Error on active extension coc-pyright

When open a python file after installed coc-pyright, the below error happened.

[coc.nvim]Error on active extension coc-pyright: Error: [UriError]: Scheme is missing: {scheme: "", authority: "", path: "/Users/yang/workspace/python-web-api-demo", query: "", f
ragment: ""}
    at _validateUri (/Users/yang/.dotfiles/dotconfig/nvim/viml/plugins/coc.nvim/build/index.js:21241:19)
    at _URI.URI (/Users/yang/.dotfiles/dotconfig/nvim/viml/plugins/coc.nvim/build/index.js:21343:13)
    at new _URI (/Users/yang/.dotfiles/dotconfig/nvim/viml/plugins/coc.nvim/build/index.js:21545:47)
    at Function.URI.parse (/Users/yang/.dotfiles/dotconfig/nvim/viml/plugins/coc.nvim/build/index.js:21455:16)
    at Configurations.getFolderConfiguration (/Users/yang/.dotfiles/dotconfig/nvim/viml/plugins/coc.nvim/build/index.js:24122:34)
    at Configurations.getConfiguration (/Users/yang/.dotfiles/dotconfig/nvim/viml/plugins/coc.nvim/build/index.js:24045:84)
    at Workspace.getConfiguration (/Users/yang/.dotfiles/dotconfig/nvim/viml/plugins/coc.nvim/build/index.js:22570:36)
    at PythonSettings.initialize (/Users/yang/.config/coc/extensions/node_modules/coc-pyright/lib/index.js:3298:52)
    at new PythonSettings (/Users/yang/.config/coc/extensions/node_modules/coc-pyright/lib/index.js:3146:14)
    at Function.getInstance (/Users/yang/.config/coc/extensions/node_modules/coc-pyright/lib/index.js:3153:30)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.