Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python lsp: Pyright isn't good #7296

Open
1 task done
lctzz540 opened this issue Feb 2, 2024 · 44 comments
Open
1 task done

Python lsp: Pyright isn't good #7296

lctzz540 opened this issue Feb 2, 2024 · 44 comments
Labels
enhancement [core label] language server An umbrella label for all language servers language An umbrella label for all programming languages syntax behaviors potential extension Functionality that could be implemented as an extension (consider moving to community extensions) python Python programming language support

Comments

@lctzz540
Copy link

lctzz540 commented Feb 2, 2024

Check for existing issues

  • Completed

Describe the feature

it should be pylsp. The pyright has issues about recognize libraries installed

If applicable, add mockups / screenshots to help present your vision of the feature

No response

@lctzz540 lctzz540 added admin read Pending admin review enhancement [core label] triage Maintainer needs to classify the issue labels Feb 2, 2024
@JosephTLyons
Copy link
Contributor

JosephTLyons commented Feb 2, 2024

Yeah, pyright has been a big source of pain for us in the Zed-Python intersection. I think we should def swap out to something better. I've not heard of pylsp, but we should def add it to the list of ones to check out:

We are working on language plugins at the moment, so, in the not-so-distant future, someone can just add these servers as plugins, but I do think we should swap out our provided one for a bettter one.

@JosephTLyons JosephTLyons added python Python programming language support language An umbrella label for all programming languages syntax behaviors language server An umbrella label for all language servers and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Feb 2, 2024
@plattenschieber
Copy link

plattenschieber commented Feb 6, 2024

Yeah, pyright has been a big source of pain for us in the Zed-Python intersection. I think we should def swap out to something better. I've not heard of pylsp, but we should def add it to the list of ones to check out:

We are working on language plugins at the moment, so, in the not-so-distant future, someone can just add these servers as plugins, but I do think we should swap out our provided one for a bettter one.

Indeed they did build a language server protocol for Ruff already ruff-lsp @JosephTLyons 🔥

@JosephTLyons
Copy link
Contributor

Yeah, pyright has been a big source of pain for us in the Zed-Python intersection. I think we should def swap out to something better. I've not heard of pylsp, but we should def add it to the list of ones to check out:

We are working on language plugins at the moment, so, in the not-so-distant future, someone can just add these servers as plugins, but I do think we should swap out our provided one for a bettter one.

Indeed they did build a language server protocol for Ruff already ruff-lsp @JosephTLyons 🔥

AFAICT, ruff-lsp only support formatting and linting as of right now, as they haven't gotten to building things out like go to def and auto-completion, but I read they will be doing that at some point.

@JosephTLyons JosephTLyons changed the title Python lsp: Pyright doesn't good Python lsp: Pyright isn't good Feb 15, 2024
@failable
Copy link

@JacobGoldenArt
Copy link

Yeah. I love Zed but when I open a Python project it's just strange. I will activate my .venv in my project directory and the script will run but when you look at the python file the imports are all red and can't be resolved.
Screenshot 2024-03-02 at 7 58 28 PM

@JacobGoldenArt
Copy link

See that python-dotenv is installed, along with pydantic in my env - (pip list) but I guess pyright is not checking for packages in the project-directory/.venv ???

@failable
Copy link

failable commented Mar 3, 2024

You need this file.

$ cat pyrightconfig.json
{
  "venvPath": ".",
  "venv": ".venv"
}

@Moshyfawn
Copy link
Contributor

There's an issue #8541 about resolving modules with Pyright.

@newtome8888
Copy link

newtome8888 commented Mar 4, 2024

I see this problem last for months, but there's still no real solution?

@JosephTLyons
Copy link
Contributor

JosephTLyons commented Mar 4, 2024

You need this file.

$ cat pyrightconfig.json
{
  "venvPath": ".",
  "venv": ".venv"
}

This should actually solve the problem - for some reason, during the migration of our documentation, we lost our Python docs that mentions this config file. I've quickly dumped the old Python docs contents into the configuration section of our website, here. I need to bring back more documentation, so I will organize this better later on.

As a side note, I want to say that we are going to be doing more for Python here shortly - we recognize just how important this language is, being one of the top most-used languages, and we want to improve for Python devs in Zed.

@newtome8888
Copy link

You need this file.

$ cat pyrightconfig.json
{
  "venvPath": ".",
  "venv": ".venv"
}

This should actually solve the problem - for some reason, during the migration of our documentation, we lost our Python docs that mentions this config file. I've quickly dumped the old Python docs contents into the configuration section of our website, here. I need to bring back more documentation, so I will organize this better later on.

As a side note, I want to say that we are going to be doing more for Python here shortly - we recognize just how important this language is, being one of the top most-used languages, and we want to improve for Python devs in Zed.

I tried it, but no luck. I use poetry in my python project, does it matter?
2024-03-04_23-04-32

@collinsinclair
Copy link

To add to the corpus of Pyright issues, in is_24hour = models.BooleanField(default=False), False is red-underlined for

Argument of type "Literal[False]" cannot be assigned to parameter "default" of type "type[NOT_PROVIDED]" in function "_init_" Type "Literal[False]" cannot be assigned to type "type[NOT_PROVIDED]"

Additionally, in def __str__(self):, __str__ is red-underlined for

Method "_str_" overrides class "Model" in an incompatible manner Return type mismatch: base method returns type "str", override returns type "CharField" "CharField" is incompatible with "str"

I have done no custom configuration. I believe these shouldn't be showing issues as they work as expected and are standard practices.

@r-cha
Copy link

r-cha commented Mar 5, 2024

I tried it, but no luck. I use poetry in my python project, does it matter?

@newtome8888 run poetry env info to find the path to your virtualenv, then add that to your pyrightconfig. Worth noting, this path will be different per machine, so don't add pyrightconfig.json to any version control. Mine looks something like this:

{
  "venvPath": "/Users/username/Library/Caches/pypoetry/virtualenvs",
  "venv": "projectname-p0LYZhue-py3.11"
}

@Moshyfawn Moshyfawn mentioned this issue Mar 5, 2024
1 task
@JosephTLyons
Copy link
Contributor

JosephTLyons commented Mar 5, 2024

I tried it, but no luck. I use poetry in my python project, does it matter?

@newtome8888 run poetry env info to find the path to your virtualenv, then add that to your pyrightconfig. Worth noting, this path will be different per machine, so don't add pyrightconfig.json to any version control. Mine looks something like this:

{
  "venvPath": "/Users/username/Library/Caches/pypoetry/virtualenvs",
  "venv": "projectname-p0LYZhue-py3.11"
}

Just to mention, there is a setting in poetry tells poetry to install the venv within the project:

Which would stabilize where the pyrightconfig.json points to, when running the project on multiple machines.

@failable
Copy link

failable commented Mar 5, 2024

Using pyright is literally painful.

@myusuf3
Copy link

myusuf3 commented Mar 8, 2024

To add to the corpus of Pyright issues, in is_24hour = models.BooleanField(default=False), False is red-underlined for

Argument of type "Literal[False]" cannot be assigned to parameter "default" of type "type[NOT_PROVIDED]" in function "init" Type "Literal[False]" cannot be assigned to type "type[NOT_PROVIDED]"

Additionally, in def __str__(self):, __str__ is red-underlined for

Method "str" overrides class "Model" in an incompatible manner Return type mismatch: base method returns type "str", override returns type "CharField" "CharField" is incompatible with "str"

I have done no custom configuration. I believe these shouldn't be showing issues as they work as expected and are standard practices.

I am running into the same issue. it's hurting more than its helping.

@didibear
Copy link

didibear commented May 2, 2024

@geoqiao pyright can be configured in the pyproject.toml directly as documented here, for example like this:

[tool.pyright]
venv = ".venv"
venvPath = "."

@geoqiao
Copy link

geoqiao commented May 2, 2024

@geoqiao pyright can be configured in the pyproject.toml directly as documented here, for example like this:

[tool.pyright]

venv = ".venv"

venvPath = "."

It still needs to be manually configured.

@vladimir-sama
Copy link

item_icon : Optional[FileStorage] = request.files.get('item_icon')
if item_icon:
  file_name : str = item_id + '.' + item_icon.filename.rsplit('.', 1)[1].lower()

Pyright: "rsplit" is not a known attribute of "None"
Good typing system? It doesn't even do TypedDict correctly

So, will there be an option system or extensions soon? I'd like Pylance but I'm not sure if it can be an extension. I've tried MyPy, but cannot remember if it was good

@tmke8
Copy link

tmke8 commented May 23, 2024

I'd like Pylance but I'm not sure if it can be an extension.

Pylance is just pyright with a few small added features. Here is a list of differences: microsoft/pylance-release#3838 (comment)

Pyright can definitely handle TypedDict. If you give more context, I can tell you what the problem is.

I agree that pyright is currently hard to set up with Zed. But with

[tool.pyright]
venvPath = "."
venv = ".venv"
# typeCheckingMode = "off"    # uncomment this if you don't want type checking

in my pyproject.toml and poetry configured with

poetry config virtualenvs.in-project true

it works very well.

@injust
Copy link
Contributor

injust commented May 29, 2024

item_icon : Optional[FileStorage] = request.files.get('item_icon')
if item_icon:
  file_name : str = item_id + '.' + item_icon.filename.rsplit('.', 1)[1].lower()

Pyright: "rsplit" is not a known attribute of "None" Good typing system? It doesn't even do TypedDict correctly

Off-topic, but @vladimir-sama your example is simply user error: FileStorage.filename can be None. See https://github.com/pallets/werkzeug/blob/3.0.3/src/werkzeug/datastructures/file_storage.pyi#L12.

@failable
Copy link

Does Zed support to config pyright to make it work with workspaces?

@jaanli
Copy link

jaanli commented Jun 1, 2024

yes, i am also having this issue :(

@JosephTLyons JosephTLyons added the potential extension Functionality that could be implemented as an extension (consider moving to community extensions) label Jun 11, 2024
@yash-desai-naik
Copy link

Just simply open the project form the terminal with env activated!!!

I faced the same issue when opening project directory directly in zed, pyright started to yell "missing libraries".

Solution:

  1. Open terminal
  2. cd YOUR_PROJECT_DIRECTORY
  3. source .venv/bin/activate
  4. zed .

now it should work smoothly

@andre0xFF
Copy link

Just simply open the project form the terminal with env activated!!!

I faced the same issue when opening project directory directly in zed, pyright started to yell "missing libraries".

Solution:

  1. Open terminal
  2. cd YOUR_PROJECT_DIRECTORY
  3. source .venv/bin/activate
  4. zed .

now it should work smoothly

doesn't work. activated the environment with poetry and still get unresolved imports.

rgbkrk added a commit that referenced this issue Jun 17, 2024
Run any Jupyter kernel in Zed on any buffer (editor):

<img width="1074" alt="image"
src="https://github.com/zed-industries/zed/assets/836375/eac8ed69-d02b-4d46-b379-6186d8f59470">

## TODO

### Lifecycle

* [x] Launch kernels on demand
* [x] Wait for kernel to be started
* [x] Request Kernel info on start
* [x] Show in progress indicator
* [ ] Allow picking kernel (it defaults to first matching language name)
* [ ] Menu for interrupting and shutting down the kernel
* [ ] Drop running kernels once editor is dropped

### Media Outputs

* [x] Render text and tracebacks with ANSI color handling
* [x] Render markdown as text
* [x] Render PNG and JPEG images using an explicit height based on
line-height
* ~~Render SVG~~ -- not happening for this PR due to lack of text in SVG
support
* [ ] Process `update_display_data` message and related `display_id`
* [x] Process `page` data from payloads as outputs
* [ ] Render markdown as, well, rendered markdown -- Note: unsure if we
can get line heights here

### Document

* [x] Select code and run
* [x] Run current line
* [x] Clear previous overlapping runs
* [ ] Support running markdown code blocks
* [ ] Action to export session as notebook or output files
* [ ] Action to clear all outputs
* [ ] Delete outputs when lines are deleted

## Other missing features

The following is a list of missing functionality or expectations that
are out of scope for this PR.

### Python Environments

Detecting python environments should probably be done in a separate PR
in tandem with how they're used with LSP. Users likely want to pick an
environment for their project, whether a virtualenv, conda env, pyenv,
poetry backed virtualenv, or the system. Related issues:

* #7646
* #7808
* #7296

### LSP Integration

* Submit `complete_request` messages for completions to interleave
interactive variables with LSP
* LSP for IPython semantics (`%%timeit`, `!ls`, `get_ipython`, etc.)

## Future release notes

- Run code in any editor, whether it's a script or a markdown document

Release Notes:

- N/A
fallenwood pushed a commit to fallenwood/zed that referenced this issue Jun 18, 2024
Run any Jupyter kernel in Zed on any buffer (editor):

<img width="1074" alt="image"
src="https://github.com/zed-industries/zed/assets/836375/eac8ed69-d02b-4d46-b379-6186d8f59470">

## TODO

### Lifecycle

* [x] Launch kernels on demand
* [x] Wait for kernel to be started
* [x] Request Kernel info on start
* [x] Show in progress indicator
* [ ] Allow picking kernel (it defaults to first matching language name)
* [ ] Menu for interrupting and shutting down the kernel
* [ ] Drop running kernels once editor is dropped

### Media Outputs

* [x] Render text and tracebacks with ANSI color handling
* [x] Render markdown as text
* [x] Render PNG and JPEG images using an explicit height based on
line-height
* ~~Render SVG~~ -- not happening for this PR due to lack of text in SVG
support
* [ ] Process `update_display_data` message and related `display_id`
* [x] Process `page` data from payloads as outputs
* [ ] Render markdown as, well, rendered markdown -- Note: unsure if we
can get line heights here

### Document

* [x] Select code and run
* [x] Run current line
* [x] Clear previous overlapping runs
* [ ] Support running markdown code blocks
* [ ] Action to export session as notebook or output files
* [ ] Action to clear all outputs
* [ ] Delete outputs when lines are deleted

## Other missing features

The following is a list of missing functionality or expectations that
are out of scope for this PR.

### Python Environments

Detecting python environments should probably be done in a separate PR
in tandem with how they're used with LSP. Users likely want to pick an
environment for their project, whether a virtualenv, conda env, pyenv,
poetry backed virtualenv, or the system. Related issues:

* zed-industries#7646
* zed-industries#7808
* zed-industries#7296

### LSP Integration

* Submit `complete_request` messages for completions to interleave
interactive variables with LSP
* LSP for IPython semantics (`%%timeit`, `!ls`, `get_ipython`, etc.)

## Future release notes

- Run code in any editor, whether it's a script or a markdown document

Release Notes:

- N/A
@geoqiao
Copy link

geoqiao commented Jun 18, 2024

Just simply open the project form the terminal with env activated!!!

I faced the same issue when opening project directory directly in zed, pyright started to yell "missing libraries".

Solution:

  1. Open terminal
  1. cd YOUR_PROJECT_DIRECTORY
  1. source .venv/bin/activate
  1. zed .

now it should work smoothly

doesn't work. activated the environment with poetry and still get unresolved imports.

This is a problem with pyright config, which has nothing to do with whether to activate the python virtual environment.

We need a better way to make pyright work without generating pyryghtconfig.json every time opening a new project.

@Act0r1
Copy link

Act0r1 commented Jun 23, 2024

You need this file.

$ cat pyrightconfig.json
{
  "venvPath": ".",
  "venv": ".venv"
}

it is not solve problem tbh

@KraXen72
Copy link

KraXen72 commented Jul 9, 2024

i'm using https://github.com/DetachHead/basedpyright in vscode and it's been great so far at replacing normal pyright or pylance. could be worth a shot.

@bluekeybo
Copy link

@JosephTLyons when will this be resolved? The python devs are suffering, in fact Zed is unusable until this is resolved. Seeing unresolved imports is a pain. Thanks!

@FilipeBisinella
Copy link
Contributor

I made a PR to allow for pyright settings, which could help with this.

#14265

@jdoss
Copy link

jdoss commented Jul 12, 2024

Is switched to https://github.com/DetachHead/basedpyright a bit a go in VSCode and it's been great. It should be a drop in replacement for pyright. ™️

Maybe make it so people can can choose between the two? One thing that is great about basedpyright is it is published as a pypi package so you can set the version you want inside of your python project.

https://docs.basedpyright.com/#/?id=published-as-a-pypi-package-no-nodejs-required

@m1guer
Copy link

m1guer commented Jul 17, 2024

placement

Hi, i have done one, but i cant test on linux(maybe a bug or skill issue), if you wanna test:
https://github.com/m1guer/basedpyright-zed

@failable
Copy link

@m1guer How to use? I select the directory on "Install Dev Extension" and nothing happens.

@m1guer
Copy link

m1guer commented Jul 17, 2024

i fixed some bugs, maybe works now.
try this in you zed settings:

{
  "languages": {
    "Python": {
     "language_servers":["!pyright","basedpyright"]
    }
  }
}

@failable
Copy link

@m1guer Just tried and does not work even with the setting. The extension does not appear in the Extension list.

@m1guer
Copy link

m1guer commented Jul 17, 2024

can open your logs?

@failable
Copy link

failable commented Jul 17, 2024

Here you go

2024-07-17T23:29:18.09519Z [INFO] compiling Rust extension /Users/user/Downloads/basedpyright-zed
2024-07-17T23:29:18.210935Z [INFO] compiling rust extension /Users/user/Downloads/basedpyright-zed
2024-07-17T23:29:18.389182Z [INFO] checking out python parser
2024-07-17T23:29:18.399757Z [ERROR] failed to compile grammar 'python'

Caused by:
    grammar directory '/Users/user/Downloads/basedpyright-zed/grammars/python' already exists, but is not a git clone of 'https://github.com/tree-sitter/tree-sitter-python'

@m1guer
Copy link

m1guer commented Jul 17, 2024

try delete the grammar folder in the extension dir and install with pip install badedpyright

@failable
Copy link

@m1guer Works like a charm.

@m1guer
Copy link

m1guer commented Jul 17, 2024

:)
has something to do.
like do all the schemas for the language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement [core label] language server An umbrella label for all language servers language An umbrella label for all programming languages syntax behaviors potential extension Functionality that could be implemented as an extension (consider moving to community extensions) python Python programming language support
Projects
None yet
Development

Successfully merging a pull request may close this issue.