MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / runCustomGetSDKCommand

Method runCustomGetSDKCommand

src/extension/sdk/utils.ts:547–575  ·  view source on GitHub ↗
(command: GetSDKCommandConfig, sdkConfigName: "dart.getDartSdkCommand" | "dart.getFlutterSdkCommand", isWorkspaceSetting: boolean)

Source from the content-addressed store, hash-verified

545 }
546
547 public async runCustomGetSDKCommand(command: GetSDKCommandConfig, sdkConfigName: "dart.getDartSdkCommand" | "dart.getFlutterSdkCommand", isWorkspaceSetting: boolean): Promise<GetSDKCommandResult> {
548 const baseWorkDir = this.getWorkingDirectoryForGetSdkCommand();
549 // No workspace open, nothing to do
550 if (!baseWorkDir) return { path: undefined };
551
552 const cmdWorkDir = command.cwd ?? ".";
553 const cmdWorkDirAbs = path.isAbsolute(cmdWorkDir) ? cmdWorkDir : path.join(baseWorkDir, cmdWorkDir);
554 try {
555 const commandResult = await runToolProcess(this.logger, cmdWorkDirAbs, command.executable, command.args ?? [], command.env);
556 if (commandResult.exitCode !== 0) {
557 throw new Error(`Exited with non-zero code (${commandResult.exitCode})`);
558 }
559 const sdkPath = commandResult.stdout.trim();
560
561 if (!sdkPath) {
562 throw new Error("No output from command");
563 }
564
565 // Check if the path exists
566 if (!fs.existsSync(sdkPath)) {
567 throw new Error(`Path does not exist: ${sdkPath}`);
568 }
569
570 return { path: sdkPath };
571 } catch (e) {
572 void this.warnIfBadSDKCommandOutput(e, cmdWorkDirAbs, sdkConfigName, isWorkspaceSetting);
573 return { error: `${e}` };
574 }
575 }
576
577 /**
578 * Obtains a sane default as a working directory for the get SDK command.

Callers 2

scanWorkspaceMethod · 0.95
runCommandFunction · 0.80

Calls 3

runToolProcessFunction · 0.90

Tested by 1

runCommandFunction · 0.64