Compare commits

...

1 Commits

Author SHA1 Message Date
openhands
5075623774 Fix issue #5746: [Bug]: Broken "Open in VSCode" button 2024-12-22 18:41:57 +00:00
2 changed files with 17 additions and 14 deletions

View File

@@ -49,12 +49,13 @@ export function FileExplorer({ isOpen, onToggle }: FileExplorerProps) {
),
);
window.open(vscodeUrl.vscode_url, "_blank");
} else if (vscodeUrl?.error) {
} else {
const errorMessage = vscodeUrl?.error || t(I18nKey.EXPLORER$VSCODE_SWITCHING_ERROR_MESSAGE, {
error: "VSCode server is not ready. Please try again in a few seconds.",
});
toast.error(
`open-vscode-error-${new Date().getTime()}`,
t(I18nKey.EXPLORER$VSCODE_SWITCHING_ERROR_MESSAGE, {
error: vscodeUrl.error,
}),
errorMessage,
);
}
};

View File

@@ -35,17 +35,19 @@ class VSCodePlugin(Plugin):
stderr=subprocess.STDOUT,
shell=True,
)
# read stdout until the kernel gateway is ready
# Wait for the VSCode server to start and be ready
output = ''
while should_continue() and self.gateway_process.stdout is not None:
line = self.gateway_process.stdout.readline().decode('utf-8')
print(line)
output += line
if 'at' in line:
break
start_time = time.time()
timeout = 30 # 30 seconds timeout
while should_continue() and time.time() - start_time < timeout:
if not check_port_available(self.vscode_port):
# Port is in use, which means server is running
logger.debug(f'VSCode server started at port {self.vscode_port}')
return
time.sleep(1)
logger.debug('Waiting for VSCode server to start...')
logger.debug(
f'VSCode server started at port {self.vscode_port}. Output: {output}'
)
if check_port_available(self.vscode_port):
logger.error('VSCode server failed to start within timeout period')
raise RuntimeError('VSCode server failed to start within timeout period')