Skip to content
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

[Docs] improve language server config instructions, including config examples for different editors #581

Open
neel04 opened this issue Aug 15, 2024 · 20 comments
Labels
config issues relating to config (pyproject.toml, pyrightconfig.json, LSP config or vscode extension) documentation Improvements or additions to documentation

Comments

@neel04
Copy link

neel04 commented Aug 15, 2024

Hi, thank you for this amazing fork. Especially loving the inlay hints with python 😄

The docs mention a couple IDEs, but not helix - how exactly can you set it up in that editor?

For reference, in helix's languages.toml, I believe you can set the analysis options like this:

[language-server.basedpyright]
command = "basedpyright-langserver"
args = ["--stdio"]

[language-server.basedpyright.config]

basedpyright.analysis.typeCheckingMode = "standard"
...
basedpyright.analysis.reportMissingTypeStubs = true
basedpyright.analysis.analyzeUnannotatedFunctions = true
basedpyright.analysis.venvPath = "/Users/neel/miniconda3/envs/react_jax"

However, how/why do we know that the toml key here happened to be basedpyright.analysis and not just specifying the config, like typeCheckingMode directly?

Plus for something like venvPath - it's not working for me, I have to activate the conda environment before I open helix in my shell to get it to work. So clearly, its the wrong key.

If you could document/explain what toml key corresponds to toggling what features, it would be really helpful for helix users setting it up, as they won't have to mess with the internal basedpyright.{json | toml} config.

Thank you so much! let me know if there's some other information you'd need from me.

cc @lemontheme who figured out the config options I'm using above :)

@KotlinIsland KotlinIsland added documentation Improvements or additions to documentation config issues relating to config (pyproject.toml, pyrightconfig.json, LSP config or vscode extension) needs investigation awaiting verification by a maintainer that the issue is valid labels Aug 15, 2024
@DetachHead
Copy link
Owner

However, how/why do we know that the toml key here happened to be basedpyright.analysis and not just specifying the config, like typeCheckingMode directly?

the language server specific options are documented here. not sure why some settings are under analysis but others aren't

Plus for something like venvPath - it's not working for me, I have to activate the conda environment before I open helix in my shell to get it to work. So clearly, its the wrong key.

try python.venvPath instead. for whatever reason i didn't update that one from python.venvPath to basedpyright.venvPath, maybe because of compatibility issues with the vscode python extension, i don't remember

@DetachHead DetachHead removed the needs investigation awaiting verification by a maintainer that the issue is valid label Aug 15, 2024
@neel04
Copy link
Author

neel04 commented Aug 15, 2024

I put it under the [language-server.basedpyright.config] as

python.venvPath = "/Users/me/miniconda3/envs/react_jax"

still doesn't work.

the language server specific options are documented here. not sure why some settings are under analysis but others aren't

Also, those are the pyright settings - not the basedpyright ones documented here. How do I configure those in my config?

@DetachHead
Copy link
Owner

the the way config is handled in (based)pyright is kind of a mess (#64). the code that reads the language server config is separate to the code that reads the pyproject.toml/pyrightconfig.json settings, but both those pages in the documentation are relevant to basedpyright, i just haven't updated all references to the name "pyright", which i guess adds to the confusion (#582)

can you see if setting venvPath and venv in pyproject.toml or pyrightconfig.json works? it would look something like this:

# pyproject.toml
[tool.basedpyright]
venvPath = "/Users/me/miniconda3/envs/react_jax"
venv = ".venv"

or

// pyrightconfig.json
{
    "venvPath": "/Users/me/miniconda3/envs/react_jax"
    "venv": ".venv"
}

note that this assumes your react_jax directory isn't the venv itself, but a directory that contains a .venv directory (i have no idea why it's like this and not just one setting...)

i also just noticed that the language server config doesn't have a python.venv option, no idea why that is either (#583)

sorry i'm probably just giving you more questions than answers lol

@neel04
Copy link
Author

neel04 commented Aug 15, 2024

No thats the directory to a conda environment, so it doesn't have a .venv there.

And it doesn't make sense to use the toml/json files as I want this setting LSP wide - so it resolves to that conda environment no matter the context of the project/folder.

@DetachHead
Copy link
Owner

that's probably the issue then. i'm not familiar with conda but it sounds like the only way to get pyright to work with it is to activate the venv first

@neel04
Copy link
Author

neel04 commented Aug 15, 2024

Cool, but what about basedpyright's own config settings? like changing reportPrivateImportUsage = false which is not a pyright config 🤔

@DetachHead
Copy link
Owner

DetachHead commented Aug 15, 2024

you mean the new rules exclusive to basedpyright like reportPrivateLocalImportUsage? they are configured the same way as the rest of the diagnostic rules: basedpyright.analysis.reportPrivateLocalImportUsage

@neel04
Copy link
Author

neel04 commented Aug 15, 2024

right so uh, that doesn't work at all for me...

image

where in my languages.toml for helix,

[language-server.basedpyright.config]
basedpyright.analysis.typeCheckingMode = "standard"
...
basedpyright.reportPrivateUsage = false

I've tried variants of this and none of them work

@DetachHead
Copy link
Owner

DetachHead commented Aug 15, 2024

you need the analysis part:

[language-server.basedpyright.config]
basedpyright.analysis.typeCheckingMode = "standard"
...
basedpyright.analysis.reportPrivateUsage = false

if that's still not working, if you happened to add a basedpyright or pyright section in pyproject.toml or a pyrightconfig.json file like i mentioned earlier, try deleting them because you may be running into #513

if that still doesn't help, i might need a self-contained repro since i'm not familiar with conda or helix. the exact steps you took to set everything up if possible

also, which version of basedpyright are you using?

@neel04
Copy link
Author

neel04 commented Aug 15, 2024

also, which version of basedpyright are you using?

The latest - I installed it yesterday from homebrew.

if that still doesn't help, i might need a self-contained repro since i'm not familiar with conda or helix. the exact steps you took to set everything up if possible

I think you can just spin up any environment, do:

brew install basedpyright
brew install helix
pip3 install jax ruff

and put this in the languages.toml:

~/.config/helix/languages.toml

[[language]]
name = "python"
scope = "source.python"
injection-regex = "python"
file-types = ["py","pyi","py3","pyw",".pythonstartup",".pythonrc"]
shebangs = ["python"]
roots = [".", "pyproject.toml", "pyrightconfig.json"]
comment-token = "#"
language-servers = ["basedpyright", "ruff"] 
indent = { tab-width = 4, unit = "    " }
auto-format = true

[language.formatter]
command = "ruff"

[language.debugger]
name = "debugpy"
transport = "stdio"
command = "python3"
args = ["-m",  "debugpy.adapter"]

[[language.debugger.templates]]
name = "source"
request = "launch"
completion = [ { name = "entrypoint", completion = "filename", default = "." } ]
args = { mode = "debug", program = "{0}" }

[language-server.basedpyright]
command = "basedpyright-langserver"
args = ["--stdio"]

[language-server.basedpyright.config]

basedpyright.analysis.typeCheckingMode = "standard"

basedpyright.analysis.autoSearchPaths = true
basedpyright.analysis.useLibraryCodeForTypes = true
basedpyright.analysis.reportMissingTypeStubs = true
basedpyright.analysis.analyzeUnannotatedFunctions = true
basedpyright.analysis.strictParameterNoneValue = true
basedpyright.analysis.reportImportCycles = true
basedpyright.analysis.reportUnreachable = true
basedpyright.analysis.reportPrivateUsage = false

[language-server.ruff]
command = "ruff-lsp"

[language-server.ruff.config.settings]
args = ["--ignore", "E402", "E731"]

[language-server.ruff.config.settings.format]
preview = true

[[language]]
name = "markdown"
formatter = { command = 'prettier', args = ["--parser", "markdown"] }
auto-format = true

helix's config.toml is irrelevant here as its only editor settings.

and then do, in a newly created py file:

import jax
jax.distributed.initialize()

No need to run it ofc, and see if it gives you a warning.

@DetachHead
Copy link
Owner

thanks, i'll play around with it and try to get back to you within a day or so. appreciate your patience, i know how much of a pain it is configuring stuff like this

@DetachHead DetachHead added the needs investigation awaiting verification by a maintainer that the issue is valid label Aug 15, 2024
@DetachHead
Copy link
Owner

sorry i dunno how i missed this. the issue was that you need to specify the diagnostic severity overrides under basedpyright.analysis.diagnosticSeverityOverrides. this works:

[language-server.basedpyright.config]
basedpyright.analysis.typeCheckingMode = "standard"
basedpyright.analysis.diagnosticSeverityOverrides.autoSearchPaths = true
basedpyright.analysis.diagnosticSeverityOverrides.useLibraryCodeForTypes = true
basedpyright.analysis.diagnosticSeverityOverrides.reportMissingTypeStubs = true
basedpyright.analysis.diagnosticSeverityOverrides.analyzeUnannotatedFunctions = true
basedpyright.analysis.diagnosticSeverityOverrides.strictParameterNoneValue = true
basedpyright.analysis.diagnosticSeverityOverrides.reportImportCycles = true
basedpyright.analysis.diagnosticSeverityOverrides.reportUnreachable = true
basedpyright.analysis.diagnosticSeverityOverrides.reportPrivateImportUsage = false

@DetachHead DetachHead removed the needs investigation awaiting verification by a maintainer that the issue is valid label Aug 17, 2024
@neel04
Copy link
Author

neel04 commented Aug 17, 2024

That works! How did you find that? and how can someone find it for other config settings as well 👍

@DetachHead
Copy link
Owner

it's mentioned in the docs for the language server settings, but it's easy to miss:

basedpyright.analysis.diagnosticSeverityOverrides [map]: Allows a user to override the severity levels for individual diagnostic rules. "reportXXX" rules in the type check diagnostics settings in configuration are supported. Use the rule name as a key and one of "error," "warning," "information," "true," "false," or "none" as value.

i should probably add some examples for how to configure these, including examples for different editors

@neel04
Copy link
Author

neel04 commented Aug 17, 2024

That would be amazing 🔥 Thank you for such prompt responses, especially during a weekend. I appreciate you taking out the time here to fix silly problems. Would definitely recommend basedpyright to all my friends ;)

PS: The inlay hints work wonderfully well. Can't believe I lived so long without them

@neel04 neel04 closed this as completed Aug 17, 2024
@DetachHead
Copy link
Owner

glad i could help, i'll keep this issue until i update the docs with helix (and other editor) specific examples

@DetachHead DetachHead reopened this Aug 17, 2024
@DetachHead DetachHead changed the title [Docs] How to setup based-pyright in helix? [Docs] improve language server config instructions, including config examples for different editors Aug 17, 2024
@summersz
Copy link

summersz commented Sep 2, 2024

I am using basedpyright with helix and rye. It works fine until I add a [tool.basedpyright] section to myproject.toml to configure it, and then it reports missing imports. I have tried adding the venv and venvPath settings that were working with pyright but with or without them basedpyright is unable to resolve imports.
Is there a helix or myproject.toml setting that I am missing?

@DetachHead
Copy link
Owner

can you send the full pyproject.toml?

@summersz
Copy link

summersz commented Sep 2, 2024

It was an issue with having left my pyright config in. It works after I removed the tool.pyright section.

# [tool.pyright]
# exclude = [ ".venv" ]
# venvPath = "."
# venv = ".venv"

[tool.basedpyright]
venvPath = "."
venv = ".venv"

@DetachHead
Copy link
Owner

yeah there should be an error warning you about that (#614)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config issues relating to config (pyproject.toml, pyrightconfig.json, LSP config or vscode extension) documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants