m1guer / basedpyright-zed

16 stars 2 forks source link

Example of how to configure initialization options #3

Closed pjv closed 3 months ago

pjv commented 3 months ago

Hi,

In my zed settings.json, I can configure the pyright initialzation options like this:

  "lsp": {
    "pyright": {
      "settings": {
        "python": {
          "pythonPath": ".venv/bin/python"
        }
      }
    },

I have tried every variation on similarly configuring basedpyright but cannot determine a viable syntax for globally configuring basedpyright. Can you show an example like the above that will set up the initialize options for the basedpyright extension?

Note that I am aware that I can create a pyrightconfig.json file in my project but that is not the solution I am looking for. I’m trying to find a way to globally configure basedpyright in my zed settings.json.

m1guer commented 3 months ago

you can create a pyproject.toml and put the all that you need inside. like this:

[tool.mypy]
plugins = ["mypy_django_plugin.main", "mypy_drf_plugin.main"]
strict = true

[tool.django-stubs]
django_settings_module = "api_naiara_joias.settings"

[tool.basedpyright]
venvPath = "../../../.cache/pypoetry/virtualenvs/"
venv = "api-naiara-joias-YxMO4wcW-py3.12"
typeCheckingMode = "basic"
reportOptionalCall = "none"
reportOptionalMemberAccess = "none"
pjv commented 3 months ago

@m1guer please re-read my “Note” in the last paragraph of my original post.

m1guer commented 3 months ago

oh, OK!

  "lsp": {
    "basedpyright": {
      "settings": {
        "python": {
          "pythonPath": ".venv/bin/python"
        }
      }
    },
m1guer commented 3 months ago

ref

pjv commented 3 months ago

@m1guer thank you!

Unfortunately, that config is the first thing I tried and it does not work. I have a small test project set up and with the above configuration, basedpyright is not finding the python install in the venv.

Here’s a couple screenshots illustrating the issue.

  1. here’s the project’s .venv environment where you can see that the woocommerce module has been installed.
SCR-20240801-jzro
  1. here’s what basedpyright does when I try to import that module: SCR-20240801-jzvw

When I view the same project with pyright using the config from my original post, it does not choke on the import woocommerce statement.

EDIT: I have also tried this config for basedpyright with the same results as above:

  "lsp": {
    "basedpyright": {
      "initialization_options": {
        "settings": {
          "python": {
            "pythonPath": ".venv/bin/python"
          }
        }
      }
    },
m1guer commented 3 months ago

oh in this case you need to use the venvPath instead of pythonPath

pjv commented 3 months ago

oh in this case you need to use the venvPath instead of pythonPath

also does not work.

m1guer commented 3 months ago

can share your logs?

pjv commented 3 months ago
2024-08-01T16:10:23.53246Z [INFO] starting language servers for Python: basedpyright, ruff
2024-08-01T16:10:23.532692Z [INFO] starting language server "basedpyright", path: "/Users/pjv/development/test/", id: 119
2024-08-01T16:10:23.532967Z [INFO] starting language server "ruff", path: "/Users/pjv/development/test/", id: 120
2024-08-01T16:10:24.157052Z [INFO] starting language server. binary path: "/usr/local/bin/ruff", working directory: "/Users/pjv/development/test/", args: ["server"]
2024-08-01T16:10:24.265434Z [INFO] starting language server. binary path: "/Users/pjv/.pyenv/shims/basedpyright-langserver", working directory: "/Users/pjv/development/test/", args: ["--stdio", ""]
2024-08-01T16:10:24.793099Z [INFO] Language server with id 119 sent unhandled notification window/logMessage:
{
  "type": 3,
  "message": "basedpyright language server 1.1.374 starting"
}
2024-08-01T16:10:24.793418Z [INFO] Language server with id 119 sent unhandled notification window/logMessage:
{
  "type": 3,
  "message": "Server root directory: file:///Users/pjv/.pyenv/versions/3.12.3/lib/python3.12/site-packages/basedpyright/dist"
}
2024-08-01T16:10:24.798941Z [INFO] Language server with id 119 sent unhandled notification window/logMessage:
{
  "type": 3,
  "message": "Starting service instance \"\""
}
2024-08-01T16:10:24.907395Z [INFO] language server 119: unregistered workspace/DidChangeWatchedFiles capability with id 6e5596e8-0348-4e2a-9ccf-410bd5306176
SCR-20240801-kgcs
m1guer commented 3 months ago

i dont know why this error is happening, im using poetry for env configs.

m1guer commented 3 months ago

https://github.com/zed-industries/zed/issues/5524

m1guer commented 3 months ago

https://docs.basedpyright.com/#/configuration

m1guer commented 3 months ago

maybe some of this articles can help you.

pjv commented 3 months ago

Thanks again. I tried reading all those docs before I posted here.

I might be wrong and I’m very deficient at reading rust code and know nothing at all about Zed’s extension api, but my guess is that the basedpyright extension may need to do something specific to parse and use the initialization_options object that zed passes to it when the LSP gets instantiated.

Here’s an example of the built-in ruff extension: https://github.com/zed-industries/zed/blob/main/extensions/ruff/src/ruff.rs

I’m thinking that this function might be what is handling the initialization options for the ruff LSP:

SCR-20240801-knjh
m1guer commented 3 months ago

thanks, will implement this rn.

m1guer commented 3 months ago

@pjv hey i will commit on a diferente brach, can you test locally for me?

pjv commented 3 months ago

I will if you can tell me how to load a development extension build in zed. I’ve only ever installed them through the standard process in zed.

m1guer commented 3 months ago

1- clone the repo on your machine. 2- switch to the another branch 3- go to zed 4- uninstall the extension 5- click on install dev extension 6- go to the place where you clone the repo and select the folder.

pjv commented 3 months ago

got it. I cloned and checked out the workspace_intialization_config and then installed it in Zed and it looks like it’s working.

Thanks for getting it fixed so quick.

m1guer commented 3 months ago

your welcome, and thanks for the suggestion. i will open a new PR to update the extension.