Skip to content

Commit

Permalink
Merge pull request #3340 from continuedev/tomasz/handle-gui-error
Browse files Browse the repository at this point in the history
Handle sidebar opening problems
  • Loading branch information
tomasz-stefaniak authored Dec 12, 2024
2 parents f990c53 + 76bf558 commit 4ba3d98
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion extensions/vscode/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,28 @@ async function processDiff(
}
}

function waitForSidebarReady(
sidebar: ContinueGUIWebviewViewProvider,
timeout: number,
interval: number,
): Promise<boolean> {
return new Promise((resolve) => {
const startTime = Date.now();

const checkReadyState = () => {
if (sidebar.isReady) {
resolve(true);
} else if (Date.now() - startTime >= timeout) {
resolve(false); // Timed out
} else {
setTimeout(checkReadyState, interval);
}
};

checkReadyState();
});
}

// Copy everything over from extension.ts
const getCommandsMap: (
ide: VsCodeIde,
Expand Down Expand Up @@ -437,18 +459,25 @@ const getCommandsMap: (
// This is a temporary fix—sidebar.webviewProtocol.request is blocking
// when the GUI hasn't yet been setup and we should instead be
// immediately throwing an error, or returning a Result object

if (!sidebar.isReady) {
focusGUI();
return;

const isReady = await waitForSidebarReady(sidebar, 5000, 100);
if (!isReady) {
return;
}
}

const historyLength = await sidebar.webviewProtocol.request(
"getWebviewHistoryLength",
undefined,
false,
);
const isContinueInputFocused = await sidebar.webviewProtocol.request(
"isContinueInputFocused",
undefined,
false,
);

if (isContinueInputFocused) {
Expand All @@ -458,13 +487,15 @@ const getCommandsMap: (
void sidebar.webviewProtocol?.request(
"focusContinueInputWithNewSession",
undefined,
false,
);
}
} else {
focusGUI();
sidebar.webviewProtocol?.request(
"focusContinueInputWithNewSession",
undefined,
false,
);
void addHighlightedCodeToContext(sidebar.webviewProtocol);
}
Expand Down

0 comments on commit 4ba3d98

Please sign in to comment.