helix
helix copied to clipboard
use pyright instead of pylsp in helix
https://github.com/helix-editor/helix/pull/834
pyright is more powerful in syntax analysis and linter
and more popular
There is only one default but you can always use a custom languages.toml configuration to switch to pyright.
If pyright is the preferred LSP by the community then you can open a PR to switch the default.
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
It should work since it's detected. Try running with hx -v then looking at the log file?
There's this: https://github.com/helix-editor/helix/discussions/5369#discussioncomment-4574449
Should be fixed now with https://github.com/helix-editor/helix/pull/5471
[[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

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?
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:

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:

@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 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, 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.
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
@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!
[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 :)
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
}
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"]
I think all actionable issuse are fixed here https://github.com/helix-editor/helix/issues/5479#issuecomment-1376970239