resolveRemoteIdeRoot function
Helpers shared by the native :ide command and a web client's :ide, kept
dart:io-free so both (CLI and browser) resolve the IDE root and pick the
agent's command syntax identically.
Resolves the remote IDE root from an optional arg and the current remote
working directory remoteCwd:
- an absolute remote (POSIX) path is normalized and used as-is;
- a relative path is joined onto
remoteCwd; - no argument (or
.) usesremoteCwditself.
Returns null when the cwd is needed (relative or omitted path) but not yet
known — the caller should ask the user to run a command first or pass an
absolute path.
Implementation
/// Resolves the remote IDE root from an optional [arg] and the current remote
/// working directory [remoteCwd]:
///
/// * an absolute remote (POSIX) path is normalized and used as-is;
/// * a relative path is joined onto [remoteCwd];
/// * no argument (or `.`) uses [remoteCwd] itself.
///
/// Returns `null` when the cwd is needed (relative or omitted path) but not yet
/// known — the caller should ask the user to run a command first or pass an
/// absolute path.
String? resolveRemoteIdeRoot(String? arg, String? remoteCwd) {
if (arg == null || arg.isEmpty || arg == '.') return remoteCwd;
if (p.posix.isAbsolute(arg)) return p.posix.normalize(arg);
if (remoteCwd == null) return null;
return p.posix.normalize(p.posix.join(remoteCwd, arg));
}