micropy-cli icon indicating copy to clipboard operation
micropy-cli copied to clipboard

Pylance Support

Open askpatrickw opened this issue 5 years ago • 8 comments

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 avatar Jul 25 '20 19:07 askpatrickw

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

BradenM avatar Jul 25 '20 20:07 BradenM

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

askpatrickw avatar Jul 26 '20 03:07 askpatrickw

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

this setting works well for me.

ShenTengTu avatar Sep 15 '20 07:09 ShenTengTu

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

krenzlin avatar Nov 02 '20 11:11 krenzlin

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 ?

Josverl avatar Nov 07 '20 22:11 Josverl

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
}

CallumJHays avatar Dec 01 '20 01:12 CallumJHays

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 : https://github.com/Josverl/micropython-stubber/issues/35

Josverl avatar Dec 01 '20 15:12 Josverl

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 avatar Dec 01 '20 21:12 BradenM