helix icon indicating copy to clipboard operation
helix copied to clipboard

use pyright instead of pylsp in helix

Open fastfading opened this issue 2 years ago • 9 comments

https://github.com/helix-editor/helix/pull/834

pyright is more powerful in syntax analysis and linter

and more popular

fastfading avatar Jan 10 '23 06:01 fastfading

There is only one default but you can always use a custom languages.toml configuration to switch to pyright.

archseer avatar Jan 10 '23 06:01 archseer

If pyright is the preferred LSP by the community then you can open a PR to switch the default.

archseer avatar Jan 10 '23 06:01 archseer

how to do that I tried

#languages.toml [[language]] name = "python" language-server = { command = "pyright", args = ["--stdio"] } formatter = { command = "pyright" , args = ["--stdin"] }

hx --health python Configured language server: pyright Binary for language server: /opt/homebrew/bin/pyright Configured debug adapter: None Highlight queries: ✓ Textobject queries: ✓ Indent queries: ✓

however it does not work

fastfading avatar Jan 10 '23 07:01 fastfading

It should work since it's detected. Try running with hx -v then looking at the log file?

archseer avatar Jan 10 '23 09:01 archseer

There's this: https://github.com/helix-editor/helix/discussions/5369#discussioncomment-4574449

archseer avatar Jan 10 '23 09:01 archseer

Should be fixed now with https://github.com/helix-editor/helix/pull/5471

archseer avatar Jan 10 '23 09:01 archseer

[[language]] name = "python" roots = ["pyproject.toml"] language-server = { command = "pyright-langserver", args = ["--stdio"] } config = {} # <- this is the important line

this works however , in vscode or neovim they will show some warning like pkg is not accessed, but in helix it won't image

fastfading avatar Jan 11 '23 08:01 fastfading

Maybe, according to the documentation we need to turn on reportUnusedImport option or set typeCheckingMode flag to "strict". But, unfortunately, I couldn't figure out how to set config in languages.toml properly. Does anyone have any ideas on this topic?

vasylnakvasiuk avatar Jan 14 '23 15:01 vasylnakvasiuk

Does anyone have any ideas on this topic?

Did you read this helix-docs? I haven't tried it, but I think you need to pass additional arguments to the config section: image

ghost avatar Jan 15 '23 11:01 ghost

Specifying any config in the languages.toml section did not work for me (as pointed out in the discussion, there is some weirdness happening with pyright). In the working directory, writing a file pyrightconfig.json like

{
 "typeCheckingMode": "strict",
  "reportMissingImports": true
}

works as expected:

image

carrascomj avatar Mar 28 '23 14:03 carrascomj

@carrascomj, is this still working for you? On the latest Helix version (23.03), it doesn't work. This is the configuration:

languages.toml

[[language]]
name = "python"
auto-format = true
language-server = { command = "pyright-langserver", args = ["--stdio"] }
config = {}

pyrightconfig.json

{
 "typeCheckingMode": "off"
}

I still get type errors in Helix, but running pyright file.py doesn't show them.

oyarsa avatar Apr 07 '23 22:04 oyarsa

@oyarsa I installed from community/helix (arch) version 23.03 and still works for me™, in the sense that the type checks are removed when I put that configuration in the root of my project.

Maybe your project root is not properly determined by helix? I tried removing the roots attribute (like in your languages.toml) and then re-adding it with a wrong field but both cases still worked for me.

carrascomj avatar Apr 08 '23 10:04 carrascomj

@carrascomj, here's what I learned:

With no roots defined, Helix/pyright (I'm not sure) looks for the git root of the repository. It only considers configuration files in the root; if you're in a subdirectory, the file is ignored. If you aren't in a git repository, it does nothing. No configuration file is loaded.

Defining roots = ["pyproject.toml"] makes it look in the current folder, then the parent, until the git root. If you're not in a git repository, it only looks in the directories between the current and the file.

Having multiple pyproject.toml files doesn't work. Say we have one in the root and one in a subdirectory that defines more settings. I expected this to merge the two files, but instead, the one closest to the file is used. I'm not sure if this is a Helix, pyright or pyright LSP limitation.

This could work if we had workspace Helix configurations that override LSP settings. For that to work, we need config to work with pyright.

oyarsa avatar Apr 08 '23 13:04 oyarsa

I've trying pyright for a while, but found it's slow for larger project, here is more information: https://github.com/microsoft/pyright/issues/1997

WindSoilder avatar May 26 '23 07:05 WindSoilder

@archseer and all other Helix contributors . It is a humble request please do not make pyright the default lsp. I have used pyright for long time and recently switched to and used pylsp and believe me that pyslp is better than pyright. Please keep pylsp as the default lsp for python in helix. We don't care about it's popularity, pylsp works well and that's what we want. Thanks!

loyalrami avatar Aug 03 '23 09:08 loyalrami

[language-server]
pyright = { command = "pyright-langserver", args = ["--stdio"], config = {} }

[[language]]
name = "python"
roots = ["pyproject.toml"]
language-servers = [ "pyright" ]

Seems to work great (with latest master) and I can add a pyrightconfig.json in the project root and it picks it up fine :)

David-Else avatar Aug 06 '23 23:08 David-Else

There is something buggy and weird going on with pyright! I have found after a lot of messing around you can't really set anything in the Helix settings, you need the external config file AND an empty config setting in Helix. Please correct me if I am wrong, but this is my final working setup:

[language-server.pyright]
command = "pyright-langserver"
args = ["--stdio"]
config = {} # buggy behaviour, you need a pyproject.toml and pyrightconfig.json

[[language]]
name = "python"
formatter = { command = "black", args = ["--quiet", "-"] }
auto-format = true
roots = ["pyproject.toml"]
language-servers = [ "pyright" ]

pyproject.toml < has to exist in the root pyrightconfig.json

{
  "typeCheckingMode": "strict",
  "reportMissingImports": true
}

David-Else avatar Aug 08 '23 12:08 David-Else

I always add my library paths to the LSP for highlighting and gd/gi bindings. In case anyone needs:

The config field in languages.toml doesn't work.

config = { extraPaths = ["./test"] } 

But, creating a pyproject.toml in root directory of your project works.

[tool.pyright]
extraPaths = ["./test"]

hakan-demirli avatar Sep 08 '23 11:09 hakan-demirli

I think all actionable issuse are fixed here https://github.com/helix-editor/helix/issues/5479#issuecomment-1376970239

pascalkuthe avatar Sep 08 '23 11:09 pascalkuthe