1 import { window } from "vscode";
2 import which from "which";
3 import type Settings from "../settings.mjs";
4 import { SettingsKey, HOME_VAR } from "../settings.mjs";
5 import { homedir } from "os";
6 import { downloadGit } from "./downloadGit.mjs";
7 import Logger, { LoggerSource } from "../logger.mjs";
10 * Shows an error message that the requirements for development are not met
11 * and lists the missing requirements.
13 * @param missing The missing requirements.
15 export async function showRequirementsNotMetErrorMessage(
18 await window.showErrorMessage(
19 "Development for the Pico requires " +
21 " to be installed and available in PATH. " +
22 "Please install and restart VS Code."
27 * Checks if a git executable is avialable or try to install if possible.
29 * @returns True if git is available, false otherwise.
31 export async function checkForGit(settings: Settings): Promise<boolean> {
32 const gitExe: string =
34 .getString(SettingsKey.gitPath)
35 ?.replace(HOME_VAR, homedir().replaceAll("\\", "/")) || "git";
37 const git: string | null = await which(gitExe, { nothrow: true });
39 let isGitInstalled = git !== null;
40 if (!isGitInstalled) {
42 const gitDownloaded: string | undefined = await downloadGit();
44 if (gitDownloaded !== undefined) {
45 // if git is downloaded set custom git path
46 await settings.updateGlobal(SettingsKey.gitPath, gitDownloaded);
47 isGitInstalled = true;
50 LoggerSource.requirements,
51 "Git is not installed and could not be downloaded."
53 void window.showErrorMessage(
54 "The installation of the Pico SDK requires Git " +
55 "to be installed and available in the PATH." +
56 (process.platform === "darwin"
57 ? " You can install it by running `xcode-select --install`" +
58 " in the terminal and restart your computer."
64 return isGitInstalled;