Files
openidea/src/features/remote-dev/model.ts
T
Andrea Basileandandreabasile 60d7dcdca0 feat(remote): reopen a local project in its dev container (#1843)
Refs #1083 (step B). A local project with a devcontainer.json can be reopened in its dev container (File › Reopen in Container, Find Action): the Dev Containers CLI brings the container up and the window connects to openidea-server inside it, as for WSL, so terminal, language servers, run, debug and git work in the container. The project's identity stays the local folder, so reopening from Recent Projects finds the same container. Missing CLI gives install guidance; trust of the local project carries over. Pure CLI output parsing lives in ide-remote; a failed connection no longer closes the current backend early, saved locations keep the container configuration, and Docker context precedence follows the CLI.

Co-authored-by: andreabasile <7715018+andreabasile@users.noreply.github.com>
2026-11-08 01:43:03 +08:00

56 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** File › Remote Development…: state of the connect dialog and the folder browser helpers. */
import { create } from "zustand";
import type { RemoteEntry, RemoteStage } from "@/platform/ipc";
export const useConnectDialog = create<{ open: boolean }>(() => ({ open: false }));
export function openConnectDialog() {
useConnectDialog.setState({ open: true });
}
export function closeConnectDialog() {
useConnectDialog.setState({ open: false });
}
/** The parent of absolute POSIX path `path` (`/` stays `/`). */
export function remoteParent(path: string): string {
const trimmed = path.replace(/\/+$/, "");
const i = trimmed.lastIndexOf("/");
return i <= 0 ? "/" : trimmed.slice(0, i);
}
/** The folders of a listing, sorted by name (hidden ones last). */
export function browsableFolders(entries: readonly RemoteEntry[]): RemoteEntry[] {
const hidden = (e: RemoteEntry) => e.name.startsWith(".");
return entries
.filter((e) => e.isDir)
.sort((a, b) => Number(hidden(a)) - Number(hidden(b)) || a.name.localeCompare(b.name));
}
/** The directory a listing of `requested` stands for (`~` resolves on the server). */
export function listedDirectory(requested: string, entries: readonly RemoteEntry[]): string {
if (requested.startsWith("/")) return requested.replace(/(.)\/+$/, "$1");
const first = entries[0];
return first ? remoteParent(first.path) : requested;
}
/** What the window is waiting for at each stage of connecting. */
export function stageLabel(stage: RemoteStage): string {
switch (stage) {
case "connecting":
return "Connecting to the host…";
case "container":
return "Starting the dev container…";
case "checking":
return "Checking the IDE backend on the host…";
case "downloading":
return "Downloading the IDE backend…";
case "uploading":
return "Installing the IDE backend on the host…";
case "starting":
return "Starting the IDE backend…";
case "opening":
return "Opening the project…";
}
}