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

Pylance Support #152

Closed
askpatrickw opened this issue Jul 25, 2020 · 8 comments · Fixed by #379
Closed

Pylance Support #152

askpatrickw opened this issue Jul 25, 2020 · 8 comments · Fixed by #379
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@askpatrickw
Copy link
Contributor

This is probably more a research project, but I wanted to put it out there to get input.

https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance

Pylance is an extension that works alongside Python in Visual Studio Code to provide performant language support. Under the hood, Pylance is powered by Pyright, Microsoft's static type checking tool. Using Pyright, Pylance has the ability to supercharge your Python IntelliSense experience with rich type information, helping you write better code faster.

Micropy-cli uses :

  • python.autoComplete.extraPaths
  • python.autoComplete.typeshedPaths
  • python.analysis.typeshedPaths

I wonder if Micropy-cli should also set similar sounding Pylance Settings

  • python.analysis.stubPath
  • python.analysis.autoSearchPaths
  • python.analysis.extraPaths

Like I said, I'm not 100%. What do you think?

@askpatrickw askpatrickw added the enhancement New feature or request label Jul 25, 2020
@BradenM
Copy link
Owner

BradenM commented Jul 25, 2020

Very interesting. Have you personally tried this? If so, how did it compare to the current ms-python + micropy stubs combo?

I've been very late putting out a release with the recent changes, so I will try and get that done today and then take a deeper look into this.

On a side note, @hlovatt recently contacted me with a new project he's working on that generates stubs with docstrings + typing parsed straight out of micropython's documentation.

See:

hlovatt/PyBoardTypeshedGenerator
And it's output:
hlovatt/PyBoardTypeshed

@askpatrickw
Copy link
Contributor Author

I've not played around with it yet in micropython

I believe Circuit Python uses a similar method to generate stubs
https://github.com/adafruit/circuitpython/issues?q=is%3Aissue+is%3Aopen+stubs

@ShenTengTu
Copy link

python.analysis.extraPaths in Pylance equivalent to current python.autoComplete.extraPaths.

this setting works well for me.

@krenzlin
Copy link

krenzlin commented Nov 2, 2020

While Pylance (v2020.10.3) now finds the stubs, it misses range and emits "range" is not definedPylance (reportUndefinedVariable)

@Josverl
Copy link

Josverl commented Nov 7, 2020

i've been looking into this from micropython-stubber to understand what needs to be done to get Lancelot happy.
i have not cracked the code on this yet.
i have a suspicion that pylance gets thrown off by the CPython-stubs, but no hard evidence yet
it would be good to have a minimal repo of where it goes wrong , so that we can whittle it down and hopefully sort it.

@ShenTengTu , as yo seem to have a working config , could you share your setup please ?

@CallumJHays
Copy link

Hey, Just gave this a quick try. removing all options but "python.analysis.extraPaths" seems to be all thats needed for setting up with pylance. Setting "python.analysis.typeShedPaths" as in the generated config appears to cause pylance's inferencing to play up.

Working config:

{
  "python.linting.enabled": true,
  "python.analysis.extraPaths": [
    ".micropy/BradenM-micropy-stubs-3cc928b/frozen",
    ".micropy/BradenM-micropy-stubs-e1b8ce6/frozen",
    ".micropy/BradenM-micropy-stubs-3cc928b/stubs",
    ".micropy/bdsim.micropython"
  ],
  "python.linting.pylintEnabled": true
}

@Josverl
Copy link

Josverl commented Dec 1, 2020

Thanks @CallumJHays , I can confirmthat pylint works better when dropping the additional paths

it may be needed to add an explicit "python.languageServer": "Pylance", depending on the user / ws preferences

{
    "python.languageServer": "Pylance",
    "python.autoComplete.extraPaths": [
        ".micropy/esp32_p1_meter",
        "src/lib",
        "all-stubs/cpython_patch",
        "all-stubs/mpy_1_13-nightly_frozen/esp32/GENERIC", 
        "all-stubs/esp32_1_13_0-103",
    ],
    "python.linting.enabled": true,
    "python.linting.pylintEnabled": true,
}

Ill update the upstream documentation tracked by : Josverl/micropython-stubber#35

@BradenM
Copy link
Owner

BradenM commented Dec 1, 2020

Awesome!

Is anyone here interested in pulling together a PR to add a template option for pylance in micropy-cli?

If not, I will try to get to it soon.

@BradenM BradenM added the help wanted Extra attention is needed label Dec 1, 2020
mwelcker pushed a commit to mwelcker/micropy-cli that referenced this issue Sep 15, 2022
BradenM pushed a commit to mwelcker/micropy-cli that referenced this issue Dec 11, 2022
BradenM pushed a commit to mwelcker/micropy-cli that referenced this issue Jan 30, 2023
BradenM pushed a commit that referenced this issue Jan 30, 2023
BradenM pushed a commit that referenced this issue Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants