Skip to content

Commit

Permalink
Data Explorer: Retry positron-duckdb.dataExplorerRpc if it has not be…
Browse files Browse the repository at this point in the history
…en registered yet (#5656)

Addresses #5655. Currently if you click on a data file while Positron is loading, it will open a broken data explorer. This awaits the command becoming available using the CommandsRegistry events and fails after 30 seconds if the command is not registered at that point.

https://github.com/user-attachments/assets/07460b8b-ef06-4c75-9b47-d93562e7690d
  • Loading branch information
wesm authored Dec 10, 2024
1 parent 3cea779 commit 763256f
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ import {
TableSchema,
TableSelection
} from 'vs/workbench/services/languageRuntime/common/positronDataExplorerComm';
import { ICommandService } from 'vs/platform/commands/common/commands';

import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/commands';

/**
* Descriptor for backend method invocation in via extension command.
Expand Down Expand Up @@ -115,9 +114,26 @@ export class PositronDataExplorerDuckDBBackend extends Disposable implements IDa

private async _execRpc<Type>(rpc: DataExplorerRpc): Promise<Type> {
await this.initialSetup;
const response = await this._commandService.executeCommand(
'positron-duckdb.dataExplorerRpc', rpc
);

const commandName = 'positron-duckdb.dataExplorerRpc';
if (CommandsRegistry.getCommand(commandName) === undefined) {
await (new Promise<void>((resolve, reject) => {
// Reject if command not registered within 30 seconds
const timeoutId = setTimeout(() => {
reject(new Error(`${commandName} not registered within 30 seconds`));
}, 30000);

CommandsRegistry.onDidRegisterCommand((id: string) => {
if (id === commandName) {
clearTimeout(timeoutId);
resolve();
}
});
}));
}

const response = await this._commandService.executeCommand(commandName, rpc);

if (response === undefined) {
return Promise.reject(
new Error('Sending request to positron-duckdb failed for unknown reason')
Expand Down

0 comments on commit 763256f

Please sign in to comment.