From b844c8096ac5ce00ebfd321d78328c122096b21d Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Mon, 17 Jun 2024 11:49:25 +0200 Subject: [PATCH] Support pyright-langserver from python package The `pyright-langserver` provided by the [`pyright` Python package](https://pypi.org/project/pyright/) is a Python script and not a NodeJS script. --- src/index.ts | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index bc17936..9972d73 100644 --- a/src/index.ts +++ b/src/index.ts @@ -69,24 +69,34 @@ export async function activate(context: ExtensionContext): Promise { window.showWarningMessage('coc-python is installed and activated, coc-pyright will be disabled'); return; } + + const runOptions = { execArgv: [`--max-old-space-size=${defaultHeapSize}`] }; + const debugOptions = { execArgv: ['--nolazy', '--inspect=6600', `--max-old-space-size=${defaultHeapSize}`] }; + + let serverOptions: ServerOptions; + let module = pyrightCfg.get('server'); if (module) { - module = which.sync(workspace.expand(module), { nothrow: true }) || module; + const serverBin = which.sync(workspace.expand(module), { nothrow: true }) || module; + if (!existsSync(serverBin)) { + window.showErrorMessage(`Pyright langserver ${serverBin} doesn't exist`); + return; + } + serverOptions = { + run: { command: serverBin, args: [...runOptions.execArgv, '--stdio'] }, + debug: { command: serverBin, args: [...debugOptions.execArgv, '--stdio'] }, + }; } else { module = join(context.extensionPath, 'node_modules', 'pyright', 'langserver.index.js'); + serverOptions = { + run: { module: module, transport: TransportKind.ipc, options: runOptions }, + debug: { module: module, transport: TransportKind.ipc, options: debugOptions }, + }; + if (!existsSync(module)) { + window.showErrorMessage(`Pyright langserver doesn't exist, please reinstall coc-pyright`); + return; + } } - if (!existsSync(module)) { - window.showErrorMessage(`Pyright langserver doesn't exist, please reinstall coc-pyright`); - return; - } - - const runOptions = { execArgv: [`--max-old-space-size=${defaultHeapSize}`] }; - const debugOptions = { execArgv: ['--nolazy', '--inspect=6600', `--max-old-space-size=${defaultHeapSize}`] }; - - const serverOptions: ServerOptions = { - run: { module: module, transport: TransportKind.ipc, options: runOptions }, - debug: { module: module, transport: TransportKind.ipc, options: debugOptions }, - }; const disabledFeatures: string[] = []; if (pyrightCfg.get('disableCompletion')) {