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

use pyright instead of pylsp in helix #5479

Closed
fastfading opened this issue Jan 10, 2023 · 19 comments
Closed

use pyright instead of pylsp in helix #5479

fastfading opened this issue Jan 10, 2023 · 19 comments
Labels
A-language-support Area: Support for programming/text languages C-enhancement Category: Improvements

Comments

@fastfading
Copy link

#834

pyright is more powerful in syntax analysis and linter

and more popular

@fastfading fastfading added the C-enhancement Category: Improvements label Jan 10, 2023
@archseer
Copy link
Member

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

@archseer
Copy link
Member

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

@fastfading
Copy link
Author

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

@archseer
Copy link
Member

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

@archseer
Copy link
Member

There's this: #5369 (reply in thread)

@archseer
Copy link
Member

Should be fixed now with #5471

@fastfading
Copy link
Author

[[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

@vasylnakvasiuk
Copy link

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?

@ghost
Copy link

ghost commented Jan 15, 2023

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

@kirawi kirawi added the A-language-support Area: Support for programming/text languages label Jan 18, 2023
@ghost ghost mentioned this issue Feb 18, 2023
@carrascomj
Copy link

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

@oyarsa
Copy link

oyarsa commented Apr 7, 2023

@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.

@carrascomj
Copy link

@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.

@oyarsa
Copy link

oyarsa commented Apr 8, 2023

@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.

@WindSoilder
Copy link
Contributor

WindSoilder commented May 26, 2023

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

@loyalrami
Copy link

@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!

@David-Else
Copy link
Contributor

[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
Copy link
Contributor

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
}

pascalkuthe pushed a commit that referenced this issue Aug 13, 2023
* Add csharp-ls for possible c-sharp LSP

See https://github.com/razzmatazz/csharp-language-server for more info
about it.

* Add pyright for possible python LSP

It may be prefered than pylsp by someone.
According to #5479, I don't
make it default for everyone. Just for people who need this.

* Update roots of python

Using some known filenames to detect correct project root.

* Add pylyzer for possible python LSP

Co-authored-by: zetashift <[email protected]>

---------

Co-authored-by: zetashift <[email protected]>
@hakan-demirli
Copy link

hakan-demirli commented Sep 8, 2023

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"]

@pascalkuthe
Copy link
Member

I think all actionable issuse are fixed here #5479 (comment)

@helix-editor helix-editor locked and limited conversation to collaborators Sep 8, 2023
@pascalkuthe pascalkuthe converted this issue into discussion #8207 Sep 8, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
A-language-support Area: Support for programming/text languages C-enhancement Category: Improvements
Projects
None yet
Development

No branches or pull requests