Skip to content

Commit

Permalink
Add second command to python client
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Aug 24, 2023
1 parent d27fb0d commit 0592362
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/examples/main/src/python/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,20 @@ const run = async () => {
// create the web socket and configure to start the language client on open
createWebSocket('ws://localhost:30000/pyright');

const registerCommand = async (cmdName: string, handler: (...args: unknown[]) => void) => {
// commands sould not be there, but it demonstrates how to retrieve list of all external commands
const commands = await vscode.commands.getCommands(true);
if (!commands.includes(cmdName)) {
vscode.commands.registerCommand(cmdName, handler);
}
};
// always exectute the command with current language client
const execServerRestart = (...args: unknown[]) => {
await registerCommand('pyright.restartserver', (...args: unknown[]) => {
languageClient.sendRequest('workspace/executeCommand', { command: 'pyright.restartserver', arguments: args });
};

// it should not be there, but it demonstrates how to retrieve list of all external commands
const commands = await vscode.commands.getCommands(true);
if (!commands.includes('pyright.restartserver')) {
vscode.commands.registerCommand('pyright.restartserver', execServerRestart);
}
});
await registerCommand('pyright.organizeimports', (...args: unknown[]) => {
languageClient.sendRequest('workspace/executeCommand', { command: 'pyright.organizeimports', arguments: args });
});

// use the file create before
const modelRef = await createModelReference(monaco.Uri.file('/tmp/hello.py'));
Expand Down

0 comments on commit 0592362

Please sign in to comment.