Git Product home page Git Product logo

Comments (38)

fannheyward avatar fannheyward commented on August 23, 2024 1

Yes, coc-python supports shebang-only.

from coc-pyright.

fannheyward avatar fannheyward commented on August 23, 2024 1

@gasull @yaegassy coc-pyright can do nothing for shebang-only Python files. Pyright can only find and analyze *.pyi? files. https://github.com/microsoft/pyright/blob/master/packages/pyright-internal/src/analyzer/service.ts#L962

coc-pyright's custom linting and formatting already support shebang-only Python files.

from coc-pyright.

fannheyward avatar fannheyward commented on August 23, 2024

I've published coc-pyright v1.1.95 with more logs added, please CocUpdate and try again.

from coc-pyright.

gasull avatar gasull commented on August 23, 2024

Same result, plus now I don't even get the default Pyright linting that I was getting before.

from coc-pyright.

yaegassy avatar yaegassy commented on August 23, 2024

@gasull

Does it show the log when I save the buffer with :w?

In my environment(venv or pipenv), when I saved the buffer, the log was displayed.

There is no problem with either v1.1.94 or v1.1.95 of coc-pyright as well.


Capture:

coc-pyright-issue202-01

from coc-pyright.

gasull avatar gasull commented on August 23, 2024

Does it show the log when I save the buffer with :w?

Yes, it shows the log and also it starts linting with all the linters.

How can I make the linters start when I open a Python file in neovim?

from coc-pyright.

yaegassy avatar yaegassy commented on August 23, 2024

@fannheyward @gasull

The linter (flake8 etc...) in coc-python seems to work when a file is opened.

It may need to be adjusted in coc-pyright.

from coc-pyright.

fannheyward avatar fannheyward commented on August 23, 2024

Lint on document open is enabled by default, maybe something is broken, will look into it.

from coc-pyright.

yaegassy avatar yaegassy commented on August 23, 2024

As you can see in my capture, pyright's lint works when the file is opened, but flake8's and other lint does not work until it is saved. :(

from coc-pyright.

yaegassy avatar yaegassy commented on August 23, 2024

coc-pyright-issue202-02

from coc-pyright.

gasull avatar gasull commented on August 23, 2024

As you can see in my capture, pyright's lint works when the file is opened, but flake8's and other lint does not work until it is saved. :(

For me neither work until the file is saved.

from coc-pyright.

yaegassy avatar yaegassy commented on August 23, 2024

@fannheyward

How about porting this from linterProvider in coc-python? https://github.com/neoclide/coc-python/blob/master/src/providers/linterProvider.ts#L50-L54

Example:

export class LinterProvider implements Disposable {

  ... snip

  public constructor(context: ExtensionContext) {

  ... snip

    setTimeout(() => this.engine.lintOpenPythonFiles().catch(this.emptyFn), 1200);
  }

  ... snip

  private emptyFn(): void {
    // noop
  }
}

It worked fine in my environment.

from coc-pyright.

yaegassy avatar yaegassy commented on August 23, 2024

Created a pull request. #206


Capture

coc-pyright-issue202-pr

from coc-pyright.

gasull avatar gasull commented on August 23, 2024

This didn't fix it for me. I still need to save the file before the linting starts.

from coc-pyright.

fannheyward avatar fannheyward commented on August 23, 2024

@gasull the PR has not been released, will publish a new release later.

from coc-pyright.

gasull avatar gasull commented on August 23, 2024

I'm installing the plugin with

Plug 'fannheyward/coc-pyright', {'do': 'yarn install --frozen-lockfile'}

and git log shows that I'm at commit 5ff22a1.

from coc-pyright.

fannheyward avatar fannheyward commented on August 23, 2024

There are two lint features provided by coc-pyright:

  • Pyright, by LSP, will lint your code LIVE, includes opening, editing, saving.
  • pylint/flake8 etc, coc-pyright will run them when document opening/saving, parse the output and return as LSP diagnostics.

@gasull please disable pylint/flake8 etc linter first, does Pyright can lint your code?

from coc-pyright.

gasull avatar gasull commented on August 23, 2024

It does not. Not even after saving the file.

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
}

from coc-pyright.

fannheyward avatar fannheyward commented on August 23, 2024

@gasull test your case with VSCode + https://marketplace.visualstudio.com/items?itemName=ms-pyright.pyright, note: you should not enable VSCode Python or Pylance, just Puright. Looks like Pyright can't work with your env.

from coc-pyright.

gasull avatar gasull commented on August 23, 2024

@gasull test your case with VSCode + https://marketplace.visualstudio.com/items?itemName=ms-pyright.pyright

My system is Debian GNU/Linux 11. I think could install Visual Studio Code from the Snap Store, but that environment would be isolated from the one in my terminal running pipenv. So I don't see how that would help debugging this problem.

from coc-pyright.

fannheyward avatar fannheyward commented on August 23, 2024

@gasull set "python.analysis.logLevel": "Trace" in coc-settings.json, and :CocCommand workspace.showOutput to check Pyright logs.

from coc-pyright.

gasull avatar gasull commented on August 23, 2024

My Pyright logs:

[Info  - 9:01:04 AM] Pyright language server 1.1.95 starting
[Info  - 9:01:04 AM] Server root directory: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/
[Info  - 9:01:04 AM] No configuration file found.
Search paths found for configured python interpreter:
  /usr/lib/python3.8
  /usr/lib/python3.8/lib-dynload
  /usr/local/lib/python3.8/dist-packages
  /usr/lib/python3/dist-packages
[Error  - 9:01:04 AM] stubPath /home/user/workspace/Electron-Cash/typings is not a valid directory.
[Info  - 9:01:04 AM] Assuming Python platform Linux
[Info  - 9:01:04 AM] Searching for source files
[Info  - 9:01:04 AM] Auto-excluding /home/user/workspace/Electron-Cash/.tox/py36
[Info  - 9:01:04 AM] Auto-excluding /home/user/workspace/Electron-Cash/.tox/py37
[Info  - 9:01:04 AM] Auto-excluding /home/user/workspace/Electron-Cash/.tox/py38
[Info  - 9:01:04 AM] Auto-excluding /home/user/workspace/Electron-Cash/.tox/py39
[Info  - 9:01:05 AM] Found 313 source files

from coc-pyright.

gasull avatar gasull commented on August 23, 2024

Even after searching for it, I don't understand what the stubPath error is about.

from coc-pyright.

fannheyward avatar fannheyward commented on August 23, 2024

You can ignore the stubPath error log, can Pyright still not lint your code?

from coc-pyright.

gasull avatar gasull commented on August 23, 2024

Sorry, I was running neovim outside of pipenv shell. The log is different now:

[Info  - 9:51:17 AM] Pyright language server 1.1.95 starting
[Info  - 9:51:17 AM] Server root directory: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/
[Info  - 9:51:17 AM] No configuration file found.
Search paths found for configured python interpreter:
  /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist
  /home/user/w/Electron-Cash
  /usr/lib/python3.8
  /usr/lib/python3.8/lib-dynload
  /home/user/.local/share/virtualenvs/Electron-Cash-lE0_HXrl/lib/python3.8/site-packages
[Error  - 9:51:17 AM] stubPath /home/user/workspace/Electron-Cash/typings is not a valid directory.
[Info  - 9:51:17 AM] Assuming Python platform Linux
[Info  - 9:51:17 AM] Searching for source files
[Info  - 9:51:17 AM] Auto-excluding /home/user/workspace/Electron-Cash/.tox/py36
[Info  - 9:51:17 AM] Auto-excluding /home/user/workspace/Electron-Cash/.tox/py37
[Info  - 9:51:17 AM] Auto-excluding /home/user/workspace/Electron-Cash/.tox/py38
[Info  - 9:51:17 AM] Auto-excluding /home/user/workspace/Electron-Cash/.tox/py39
[Info  - 9:51:17 AM] Found 313 source files
[FG] analyzing: /home/user/workspace/Electron-Cash/electroncash/address.py ...
[FG]   parsing: /home/user/workspace/Electron-Cash/electroncash/address.py (136ms)
[FG]   parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/builtins.pyi [fs read 11ms] (175ms)
[FG]   binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/builtins.pyi (65ms)
[FG]   binding: /home/user/workspace/Electron-Cash/electroncash/address.py (17ms)
[FG]   checking: /home/user/workspace/Electron-Cash/electroncash/address.py ...
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/collections/__init__.pyi [fs read 3ms] (42ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/collections/__init__.pyi (14ms)
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/_typeshed/__init__.pyi [fs read 9ms] (34ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/_typeshed/__init__.pyi (2ms)
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/third_party/2and3/typing_extensions.pyi [fs read 0ms] (3ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/third_party/2and3/typing_extensions.pyi (2ms)
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/typing.pyi [fs read 0ms] (41ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/typing.pyi (36ms)
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/hashlib.pyi [fs read 7ms] (19ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/hashlib.pyi (15ms)
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/struct.pyi [fs read 1ms] (2ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/struct.pyi (2ms)
[FG]     parsing: /home/user/workspace/Electron-Cash/electroncash/cashaddr.py [fs read 1ms] (9ms)
[FG]     binding: /home/user/workspace/Electron-Cash/electroncash/cashaddr.py (4ms)
[FG]     parsing: /home/user/workspace/Electron-Cash/electroncash/networks.py [fs read 1ms] (12ms)
[FG]     binding: /home/user/workspace/Electron-Cash/electroncash/networks.py (4ms)
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/enum.pyi [fs read 0ms] (2ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/enum.pyi (4ms)
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/abc.pyi [fs read 0ms] (1ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/abc.pyi (0ms)
[FG]     parsing: /home/user/workspace/Electron-Cash/electroncash/bitcoin.py [fs read 0ms] (111ms)
[FG]     binding: /home/user/workspace/Electron-Cash/electroncash/bitcoin.py (22ms)
[FG]     parsing: /home/user/workspace/Electron-Cash/electroncash/util.py [fs read 1ms] (95ms)
[FG]     binding: /home/user/workspace/Electron-Cash/electroncash/util.py (13ms)
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/array.pyi [fs read 7ms] (12ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/array.pyi (2ms)
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/mmap.pyi [fs read 1ms] (2ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/mmap.pyi (1ms)
[FG]     parsing: /home/user/workspace/Electron-Cash/electroncash/asert_daa.py [fs read 7ms] (10ms)
[FG]     binding: /home/user/workspace/Electron-Cash/electroncash/asert_daa.py (2ms)
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/json/__init__.pyi [fs read 1ms] (2ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/json/__init__.pyi (1ms)
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/json/decoder.pyi [fs read 0ms] (1ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/json/decoder.pyi (1ms)
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/pkgutil.pyi [fs read 1ms] (3ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/pkgutil.pyi (3ms)
[FG]     parsing: /home/user/.local/share/virtualenvs/Electron-Cash-lE0_HXrl/lib/python3.8/site-packages/ecdsa/__init__.py [fs read 7ms] (8ms)
[FG]     binding: /home/user/.local/share/virtualenvs/Electron-Cash-lE0_HXrl/lib/python3.8/site-packages/ecdsa/__init__.py (0ms)
[FG]     parsing: /home/user/.local/share/virtualenvs/Electron-Cash-lE0_HXrl/lib/python3.8/site-packages/ecdsa/util.py [fs read 1ms] (14ms)
[FG]     binding: /home/user/.local/share/virtualenvs/Electron-Cash-lE0_HXrl/lib/python3.8/site-packages/ecdsa/util.py (12ms)
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/binascii.pyi [fs read 1ms] (4ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/binascii.pyi (0ms)
[FG]     parsing: /home/user/.local/share/virtualenvs/Electron-Cash-lE0_HXrl/lib/python3.8/site-packages/ecdsa/ecdsa.py [fs read 1ms] (13ms)
[FG]     binding: /home/user/.local/share/virtualenvs/Electron-Cash-lE0_HXrl/lib/python3.8/site-packages/ecdsa/ecdsa.py (3ms)
[FG]     parsing: /home/user/.local/share/virtualenvs/Electron-Cash-lE0_HXrl/lib/python3.8/site-packages/ecdsa/ellipticcurve.py [fs read 1ms] (43ms)
[FG]     binding: /home/user/.local/share/virtualenvs/Electron-Cash-lE0_HXrl/lib/python3.8/site-packages/ecdsa/ellipticcurve.py (12ms)
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/third_party/3/six/__init__.pyi [fs read 7ms] (26ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/third_party/3/six/__init__.pyi (4ms)
[FG]     parsing: /home/user/.local/share/virtualenvs/Electron-Cash-lE0_HXrl/lib/python3.8/site-packages/ecdsa/_compat.py [fs read 1ms] (11ms)
[FG]     binding: /home/user/.local/share/virtualenvs/Electron-Cash-lE0_HXrl/lib/python3.8/site-packages/ecdsa/_compat.py (1ms)
[FG]     parsing: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/re.pyi [fs read 2ms] (5ms)
[FG]     binding: /home/user/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/typeshed-fallback/stdlib/3/re.pyi (2ms)
[FG]     parsing: /home/user/.local/share/virtualenvs/Electron-Cash-lE0_HXrl/lib/python3.8/site-packages/ecdsa/_rwlock.py [fs read 0ms] (6ms)
[FG]     binding: /home/user/.local/share/virtualenvs/Electron-Cash-lE0_HXrl/lib/python3.8/site-packages/ecdsa/_rwlock.py (1ms)
[FG]     parsing: /home/user/.local/share/virtualenvs/Electron-Cash-lE0_HXrl/lib/python3.8/site-packages/ecdsa/numbertheory.py [fs read 8ms] (76ms)
[FG]     binding: /home/user/.local/share/virtualenvs/Electron-Cash-lE0_HXrl/lib/python3.8/site-packages/ecdsa/numbertheory.py (12ms)
[FG]   checking: /home/user/workspace/Electron-Cash/electroncash/address.py (2565ms)
[Info  - 9:51:21 AM] [FG] Long operation: checking: /home/user/workspace/Electron-Cash/electroncash/address.py (2565ms)
[FG] analyzing: /home/user/workspace/Electron-Cash/electroncash/address.py (2966ms)
[Info  - 9:51:21 AM] [FG] Long operation: analyzing: /home/user/workspace/Electron-Cash/electroncash/address.py (2966ms)

from coc-pyright.

fannheyward avatar fannheyward commented on August 23, 2024

The logs show that Pyright works for your code. Does pylint/flake8 still can not lint your code?

from coc-pyright.

gasull avatar gasull commented on August 23, 2024

can Pyright still not lint your code?

I found something interesting.

In a Python executable file, that doesn't end in .py, Pyright doesn't work at all, even after saving the file.

In Python files with the .py extension Pyright works when opening the file, but the extra linters only work after saving the file.

from coc-pyright.

fannheyward avatar fannheyward commented on August 23, 2024

coc-pyright can only work for python file, check your filetype.

from coc-pyright.

gasull avatar gasull commented on August 23, 2024

coc-pyright can only work for python file, check your filetype.

It's a python file with the Python 3 hashbang at the top. But the name of the file doesn't end in .py. Neovim still recognizes it as Python file and I get syntax coloring.

You also ignored that for files ending in .py the extra linters only work after saving the file.

from coc-pyright.

fannheyward avatar fannheyward commented on August 23, 2024

@gasull what's the output of :verbose set filetype??

from coc-pyright.

gasull avatar gasull commented on August 23, 2024

Both files are recognized as Python files, with exactly the same output.

On electron-cash file (no .py extension, but executable with Python hashbang.):

  filetype=python
        Last set from /usr/share/nvim/runtime/scripts.vim line 125       

On a Python file named address.py:

  filetype=python
        Last set from /usr/share/nvim/runtime/scripts.vim line 125    

from coc-pyright.

fannheyward avatar fannheyward commented on August 23, 2024

@gasull try to set :h g:coc_filetype_map

from coc-pyright.

yaegassy avatar yaegassy commented on August 23, 2024

I checked that shebang-only (e.g. #!/usr/bin/env python3) python files don't seem to work with pyright completion, linting, and other features.

I tried to use pyright-langserver with another LSP client plug-in, vim-lsp, but it was the same, so it seems to be a specification of pyright-langserver.

from coc-pyright.

yaegassy avatar yaegassy commented on August 23, 2024

However, VSCode's pyright extension worked even with shebang-only, so maybe VSCode is running some special feature.

from coc-pyright.

yaegassy avatar yaegassy commented on August 23, 2024

Oh, excuse me. There was a mistake in my verification. the python extension was working together with the pyright extension in VSCode, so I stopped the python extension, and it didn't work with the shebang-only python file.

It still looks like a specification of pyright-langserver.


As a side note, the [deprecated] coc-python extension also seems to work with shebang-only.

from coc-pyright.

yaegassy avatar yaegassy commented on August 23, 2024

Shebang-only python files are now supported in pyright 1.1.98.

from coc-pyright.

gasull avatar gasull commented on August 23, 2024

Yes, it works now. Thank you!

(It takes a long time for me to start linting, but that might be my system).

from coc-pyright.

gasull avatar gasull commented on August 23, 2024

To clarify:

Both Pyright and extra linters work, and both on shebang-only files and on .py files.

from coc-pyright.

Related Issues (20)

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.