Skip to content

Instantly share code, notes, and snippets.

@nullchilly
Last active June 18, 2024 10:47
Show Gist options
  • Save nullchilly/91fb9d5bf410350d23dd8f4369e5183a to your computer and use it in GitHub Desktop.
Save nullchilly/91fb9d5bf410350d23dd8f4369e5183a to your computer and use it in GitHub Desktop.
Add pylance to coc.nvim

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
      }
    }
  }
}
@pearagit
Copy link

has anyone tried this and basedpyright and could comment on how they compare? thank you

@igorlfs
Copy link

igorlfs commented May 10, 2024

Hey @pearagit, IMO, basedpyright's major drawback is that it's really, really slow. Everything from completion to hover just takes forever when compared to Pylance.

But hey fellas, has anyone noticed some issues with semantic highlighting when using Pylance with neovim's built-in LSP?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment