collective / collective.recipe.vscode

Buildout Recipe for Visual Studio Code
8 stars 7 forks source link

Add supports for Microsoft Pylance #18

Open nazrulworld opened 3 years ago

nazrulworld commented 3 years ago

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

NicolasGoeddel commented 3 years ago

I figured out that it PyLance works out of the box if you simply specify zopepy instead of python as your default interpreter. When I work on Plone projects I have often checked out multiple packages in the src folder. Therefore I use one workspace file with one folder for my home directory and then for every source an other folder. in the end it looks like this:

{
    "folders": [
        {
            "path": "."
        },
        {
            "path": "Plone/zeocluster/src/my.addon1"
        },
        {
            "path": "Plone/zeocluster/src/my.addon2"
        }
    ],
    "settings": {
        "files.associations": {
            "*.zcml": "xml"
        },
        "python.pythonPath": "~/Plone/zeocluster/bin/zopepy",
        "files.exclude": {
            "**/__pycache__": true
        },
        "files.watcherExclude": {
            "**/var/blobstorage/**": true,
            "**/var/filestorage/**": true,
        },
        "git.autofetch": true
    }
}

I save this file as workspace.code-workspace in the home directory and open it with VSCode. Just make sure that the path to zopepy is absolute because otherwise Pylance will throw errors.

You do not even need collective.recipe.vscode anymore. Autocompletion just works because zopepy already knows all the things you need.