zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
47.2k stars 2.72k forks source link

Pyright python suggestions not work properly #17530

Open giovanniOfficioso opened 1 week ago

giovanniOfficioso commented 1 week ago

Check for existing issues

Describe the bug / provide steps to reproduce it

The suggestion in pyright don't work properly, both with base and local environment. I'm on miniconda. No suggestion and a problem, that not exists really, highlighted by pyright.

I'm working with virtual environment using conda, but the issue still in the base environment. Is possible to fix it? Here is also my setting:

{
  "vim_mode": true,
  "telemetry": {
    "diagnostics": false,
    "metrics": false
  },
  "ui_font_size": 16,
  "buffer_font_size": 13,
  "buffer_font_family": "MesloLGS NF",
  "buffer_font_weight": 400,
  "ui_font_features": {
    "calt": true
  },
  "buffer_font_features": {
    "ss02": true
  },
  "theme": {
    "mode": "system",
    "light": "One Dark Vivid",
    "dark": "One Dark Vivid"
  },
  "lsp": {
    "ruff": {
      "initialization_options": {
        "settings": {
          "lineLength": 80,
          "lint": {
            "extendSelect": ["I"]
          }
        }
      }
    }
  },
  "languages": {
    "Python": {
      "format_on_save": "on",
      "formatter": [
        {
          "code_actions": {
            "source.organizeImports.ruff": true,
            "source.fixAll.ruff": true
          }
        }
      ],
      "tab_size": 4,
      "language_servers": ["ruff", "pyright"]
    }
  },
  "current_line_highlight": "all",
  "show_whitespaces": "all",
  "indent_guides": {
    "enabled": true,
    "line_width": 1,
    "active_line_width": 1,
    "coloring": "indent_aware",
    "background_coloring": "indent_aware"
  },
  "show_wrap_guides": true,
  "terminal": {
    "font_family": "MesloLGS NF"
  },
  "cursor_blink": true
}

Environment

Zed: v0.152.1 (Zed Preview) OS: macOS 13.6.7 Memory: 32 GiB Architecture: aarch64

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

When I write the code here is as it appears in zed: Screenshot 2024-09-07 at 12 34 30

Here is the same windows in fleet editor, with both linter and suggestions which work properly: Screenshot 2024-09-07 at 12 35 18

If applicable, attach your Zed.log file to this issue.

Zed.log


mak448a commented 1 week ago

You need to add it to your settings. "show_completions_on_input": true,. Let me know if it worked! Please close the issue if it did. I also opened #17555, if you're interested.

giovanniOfficioso commented 1 week ago

Hi man, also with your suggestion, the issue still. Pyright doesn't provide suggestion based on what I code, but only on standard libraries that I installed in the virtual environment. Screenshot 2024-09-08 at 10 55 06 As you can see I have no suggestion for the "df" object, but in other tools it there is. Not only fleet, also in VSCode, as you can see from the following screen. Screenshot 2024-09-08 at 10 57 02 So the issue still both for suggestion and for the inexistent highlighted error.

sdhmh commented 1 week ago

Did you create your pyrightconfig.json in the root of your repository?

You will have to link it to your conda env

For example, with ~/miniconda3/ as the base directory where miniconda is installed you have to create a pyrightconfig.json like this:

{
  "venv": "env_name",
  "venvPath": "~/miniconda3/envs/"
}

You will have to change the path if you have installed it globally (like /opt/miniconda3/envs/)

If you are using anaconda the directory might be anaconda. (Double check it)

giovanniOfficioso commented 1 week ago

Yes, I did. I have a pyrightconfig in each different folder for each different project. Indeed the imports are not highlighted, so the libraries installed are recognized. However the suggestions don’t work as I showed in the previous images. If I define any object as a pandas dataframe, then I have no suggestion as I showed and it is very difficult to code without knowing each library in a deep way, that is impossible.

Moshyfawn commented 5 days ago

I see your issue #16076 from 11 August reporting a similar problem. Based on the configuration you provided, it appears that you are reporting the same issue. Is this correct?

giovanniOfficioso commented 5 days ago

The issues are different because if I install ruff, pyright doesn’t work because it doesn’t provide any suggestion. So they seem incompatible. If I install only pyright, the suggestions are very poor if they are compared with the other ones provided in other tools and also the code checker doesn’t work in the right way because it highlights errors which really don’t exists. The main problems appears to be pyright here and it would be awesome if we could have alternatives such as Jedi in order to have a better coding experience.

sdhmh commented 5 days ago

yes I had the exact same issue when I installed ruff as an extension in zed.

But using these options in my settings.json I was able to get both ruff (formatting) and pyright (linting and suggestions) working together.

(Note: Ruff is still not installed as an extension)

"languages": {
    "Python": {
      "format_on_save": {
        "external": {
          "command": "bash",
          "arguments": [
            "-c",
            "ruff check --select I --fix --stdin-filename {buffer_path} | ruff format --stdin-filename {buffer_path}"
          ]
        }
      }
    }
  },

This uses Ruff as (just) the formatter and Pyright as the language server.

EDIT: I got suggestions in the editor while Ruff was installed as an extension by pressing CTRL + SPACE. But the import suggestions were not working (typing urlretrieve wouldn't give a suggestion to import it directly from urllib.request)

brendan-corrigan commented 1 day ago

The issues are different because if I install ruff, pyright doesn’t work because it doesn’t provide any suggestion. So they seem incompatible. If I install only pyright, the suggestions are very poor if they are compared with the other ones provided in other tools and also the code checker doesn’t work in the right way because it highlights errors which really don’t exists. The main problems appears to be pyright here and it would be awesome if we could have alternatives such as Jedi in order to have a better coding experience.

This issue has some weird behaviour, I believe it has to do with the order they are loaded in.

I managed to get around this by changing the order when specifying language servers.

Going from: "language_servers": ["ruff", "pyright"] To: "language_servers": ["pyright", "ruff"]

giovanniOfficioso commented 3 hours ago

After changing nothing work, no suggestion and worse code checking