Install the pylance extension in vscode or manually download it from the marketplace
The extension path should be similar to this: ~/.vscode/extensions/ms-python.vscode-pylance-2023.11.10
In init.vim
, this will automatically detect the latest pylance version because after an upgrade the old plugin might linger for a while:
call coc#config('languageserver', { "pylance": { "module": expand("~/.vscode/extensions/ms-python.vscode-pylance-*/dist/server.bundle.js", 0, 1)[0] } })
In coc-settings.json
, we add these env
to trick pylance into thinking we are running vscode:
{
"languageserver": {
"pylance": {
"enable": true,
"filetypes": [
"python"
],
"env": {
"ELECTRON_RUN_AS_NODE": "0",
"VSCODE_NLS_CONFIG": "{\"locale\": \"en\"}"
},
"module": "${userHome}/.vscode/extensions/ms-python.vscode-pylance-2023.11.10/dist/server.bundle.js",
"initializationOptions": {},
"settings": {
"python.analysis.typeCheckingMode": "basic",
"python.analysis.diagnosticMode": "openFilesOnly",
"python.analysis.stubPath": "./typings",
"python.analysis.autoSearchPaths": true,
"python.analysis.extraPaths": [],
"python.analysis.diagnosticSeverityOverrides": {},
"python.analysis.useLibraryCodeForTypes": true
}
}
}
}
Yup, I investigated this my looking at the LSP logs. No matter what I do I can't get inlay hints to work on latest nvim nightly. I can see in the telemetry LSP notification emitted after pylance starts inlay hints are always disabled no matter my settings. My guess is it's running some kind of off-books capabilities check that nvim doesn't pass and turning it off.
I also can't configure
typeCheckingMode
via lang server settings, though I can with a pyright config file.