Skip to content

Commit

Permalink
Support pyright-langserver from python package
Browse files Browse the repository at this point in the history
The `pyright-langserver` provided by the [`pyright` Python
package](https://pypi.org/project/pyright/) is a Python script and not a
NodeJS script.
  • Loading branch information
geigerzaehler committed Jun 17, 2024
1 parent a61c902 commit b844c80
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,34 @@ export async function activate(context: ExtensionContext): Promise<void> {
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<string>('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<boolean>('disableCompletion')) {
Expand Down

0 comments on commit b844c80

Please sign in to comment.