Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Closed
1 task done
lctzz540 opened this issue Feb 2, 2024 · 73 comments
Closed
1 task done

Python lsp: Pyright isn't good #7296

lctzz540 opened this issue Feb 2, 2024 · 73 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
Collaborator

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
Collaborator

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
Member

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
Collaborator

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
Collaborator

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.

@m1guer
Copy link

m1guer commented Jul 23, 2024

@m1guer Thanks for bringing basedpyright to Zed!

For those curious, the extension is under review at zed-industries/extensions#1080

your welcome, im just waiting for the review approvement. i fixed all the bugs related to the schema.

@hirako2000
Copy link

hirako2000 commented Jul 30, 2024

neither pyright.json and myproject.toml with the pyright setting worked for me.
In case someone faces the same fate this fixed it:

mkdir .zed # in the root folder of the project
touch .zed/settings.json

in that settings.json, having installed ruff as linter.

{
  "tools": {
    "ruff": {
      "command": "ruff",
      "args": ["--format", "json", "--stdin-filename", "$FILENAME", "-"],
      "rootPatterns": ["pyproject.toml", "setup.cfg", ".git"],
      "filePatterns": ["*.py"],
      "runOnSave": true,
      "errorPatterns": [
        {
          "regexp": "^(.*?):(\\d+):(\\d+): (.*)$",
          "file": 1,
          "line": 2,
          "column": 3,
          "message": 4
        }
      ]
    }
  }
}

if using another linter, adjust accordingly.

@chrisemke
Copy link

Is there any chance of support for the mypy daemon?
I currently use ruff and mypy together in vscodium, it would be nice to have the mypy information inside the editor as well using dmypy

https://mypy.readthedocs.io/en/stable/mypy_daemon.html

@andre0xFF
Copy link

neither pyright.json and myproject.toml with the pyright setting worked for me. In case someone faces the same fate this fixed it:

mkdir .zed # in the root folder of the project
touch .zed/settings.json

in that settings.json, having installed ruff as linter.

{
  "tools": {
    "ruff": {
      "command": "ruff",
      "args": ["--format", "json", "--stdin-filename", "$FILENAME", "-"],
      "rootPatterns": ["pyproject.toml", "setup.cfg", ".git"],
      "filePatterns": ["*.py"],
      "runOnSave": true,
      "errorPatterns": [
        {
          "regexp": "^(.*?):(\\d+):(\\d+): (.*)$",
          "file": 1,
          "line": 2,
          "column": 3,
          "message": 4
        }
      ]
    }
  }
}

if using another linter, adjust accordingly.

it's pyrightconfig.json on the project root

@v3ss0n
Copy link

v3ss0n commented Aug 21, 2024

Any updates here? current pyright in Zed is down right disapponting .
Need BasedPyRIght + Ruff + MyPY.

@m1guer
Copy link

m1guer commented Aug 21, 2024

ruff and basedpyright are on extensions.

@rgbkrk
Copy link
Member

rgbkrk commented Aug 21, 2024

I don't want people to be burdened by too much choice but I put together an extension using python-lsp-server you can try by installing as a dev extension: https://github.com/rgbkrk/python-lsp-zed-extension

Thus far I'm enjoying it and it feels like one I should submit to the extensions repo. python-lsp-server has mypy support but I've yet to see it working in practice. Happy to hack with folks on it!

@bersace
Copy link

bersace commented Aug 23, 2024

Wow, pyright eats 3.5G of RAM after a few days. Never had this with jedi.

@bersace
Copy link

bersace commented Aug 23, 2024

Thus far I'm enjoying it and it feels like one I should submit to the extensions repo. python-lsp-server has mypy support but I've yet to see it working in practice. Happy to hack with folks on it!

How to disable pyright and move to pylsp ?

maxdeviant added a commit to zed-industries/extensions that referenced this issue Aug 23, 2024
Add https://github.com/rgbkrk/python-lsp-zed-extension as another Python
LSP option. Motivated by requests and pain points in
zed-industries/zed#7296.

---------

Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
@rgbkrk
Copy link
Member

rgbkrk commented Aug 23, 2024

You can now search for "Python LSP" in extensions to enable it.

image

Note that you will need to install the python lsp server directly first.

Read more in the python-lsp-zed-extension README and file issues there. I'm still figuring out what else I can enable. I would ❤️ if someone gets mypy configuration working with it.

@a-kachurin
Copy link

You can now search for "Python LSP" in extensions to enable it.

image

Note that you will need to install the python lsp server directly first.

Read more in the python-lsp-zed-extension README and file issues there. I'm still figuring out what else I can enable. I would ❤️ if someone gets mypy configuration working with it.

Is the "Go to Definition" feature implemented in your plugin? I would like to try Zed on Win11. Could you please provide more detailed instructions on how to set up the plugin?

@lucianosrp
Copy link

Is the "Go to Definition" feature implemented in your plugin? I would like to try Zed on Win11.

Even with pylsp and basedpyright I am still not able to "Go to Definition" on Windows 11

@failable
Copy link

Has anyone successfully started pylsp and been able to use the code completion feature? Even though I installed python-lsp-server, I still can't use any of its functions.

@vrslev
Copy link

vrslev commented Sep 30, 2024

@failable You should also have pylsp installed—then it works

@failable
Copy link

@vrslev

Even though I installed python-lsp-server

@vrslev
Copy link

vrslev commented Sep 30, 2024

Do you have it in PATH?

@fabioz
Copy link

fabioz commented Sep 30, 2024

Question (I can open a different issue if needed, but I thought asking here is Ok, if not, please let me know).

I have my own language server that I do for Python (https://marketplace.visualstudio.com/items?itemName=fabioz.vscode-pydev), how can I stop using the builtin one to use my own?

-- i.e.: if I register another Python extension (as in https://github.com/rgbkrk/python-lsp-zed-extension/), will it stop using the builtin one, which is giving me pyright errors?

@Herraj
Copy link

Herraj commented Nov 20, 2024

Looks like pylsp was added as of today: #20358. Also mentioned in the release notes!

also see issue: #20646

@JaagupAverin
Copy link
Contributor

JaagupAverin commented Nov 23, 2024

Since pyright and basedpyright don't support formatting, I agree with implementing pylsp as default
...
I'd appreciate any thoughts on this approach.

My only gripe with pylsp is that, as of today, basedpyright is a more fleshed out type checker with more features such as inlay hints, and a very active developer who's pushing patches on a weekly basis, whereas pylsp seems to be a bit stale and features such as inlay hints are still missing.

Furthermore from my perspective having the formatter (Ruff) in parallel to the LSP is a more flexible experience than having the formatter hierarchically under the the LSP (as a plugin). But I am not well acquainted with the technicalities of this topic so perhaps there is a performance/scaling consideration that I'm not aware of.

@ryukinix
Copy link

ryukinix commented Dec 9, 2024

There is any simple way to replace pyright with mypy? Pyright being the default is kinda a deal breaker for me.

@osiewicz
Copy link
Contributor

osiewicz commented Dec 9, 2024

You can use mypy with pylsp that's the other language server provided out of the box.

@smparekh
Copy link

smparekh commented Jan 7, 2025

for macOS using pylsp with ruff, here is my setup:

...
  "languages": {
    "Python": {
      "language_servers": ["pylsp", "!pyright", "..."],
      "preferred_line_length": 120
    }
  },
  "lsp": {
    "pylsp": {
      "binary": {
        "path": "/Users/<USERNAME>/.local/bin/pylsp"
      },
      "settings": {
        "plugins": {
          "ruff": {
            "enabled": true,
            "formatEnabled": true,
            "lineLength": 120,
            "targetVersion": "py311"
          }
        }
      }
    },
...

Install python-lsp-ruff:

pipx install python-lsp-ruff --include-deps

@g0di
Copy link

g0di commented Jan 20, 2025

Furthermore from my perspective having the formatter (Ruff) in parallel to the LSP is a more flexible experience than having the formatter hierarchically under the the LSP (as a plugin). But I am not well acquainted with the technicalities of this topic so perhaps there is a performance/scaling consideration that I'm not aware of.

I can rely on that. I've give a try to python-lsp-ruff plugin to use only pylsp as my one and only language server in Zed for python and it appeared that formatting (and code fixes) were lot more slower (more than a second) compared to using directly the ruff lsp (instantaneous) next to pylsp or pyright for handling the rest. I don't know if I'm the only one noticing this.

By the way, I actually have to use pyright, pylsp and ruff servers next to each others in my Zed config because using only pylsp and ruff does not provide any autocompletion anymore... Not sure why. So pyright gives me autocompletion (and more), pylsp gives me mypy type checking (through plugin) and ruff gives me linting and formatting.

Not sure if this is the best config but it works as intended. Just my 2 cents experience.

@zed-industries zed-industries locked and limited conversation to collaborators Jan 20, 2025
@notpeter notpeter converted this issue into discussion #23376 Jan 20, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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.