<commit_before>import * as fs from "fs";
import * as path from "path";
import * as vs from "vscode";
import { doNotAskAgainAction, noRepeatPromptThreshold, noThanksAction, openDevToolsAction, wantToTryDevToolsPrompt } from "./constants";
import { Context } from "./context";
import { flutterExtensionIdentifier } from "./debug/utils";
import { StagehandTemplate } from "./pub/stagehand";
import { DART_STAGEHAND_PROJECT_TRIGGER_FILE, extensionVersion, FLUTTER_CREATE_PROJECT_TRIGGER_FILE, FLUTTER_STAGEHAND_PROJECT_TRIGGER_FILE, fsPath, getDartWorkspaceFolders, hasFlutterExtension, isDevExtension, openInBrowser, reloadExtension, WorkspaceContext } from "./utils";

const promptPrefix = "hasPrompted.";
const installFlutterExtensionPromptKey = "install_flutter_extension_2";

export function showUserPrompts(context: Context, workspaceContext: WorkspaceContext): void {
	handleNewProjects(context);

	function shouldSuppress(key: string): boolean {
		const stateKey = `${promptPrefix}${key}`;
		return context.get(stateKey) === true;
	}

	/// Shows a prompt and stores the return value. Prompt should return `true` to mark
	/// this extension as seen-forever and it won't be shown again. Returning anything
	/// else will allow the prompt to appear again next time.
	function showPrompt(key: string, prompt: () => Thenable<boolean>): void {
		const stateKey = `${promptPrefix}${key}`;
		prompt().then((res) => context.update(stateKey, res), error);
	}

	const versionLink = extensionVersion.split(".").slice(0, 2).join(".").replace(".", "-");
	const releaseNotesKeyForThisVersion = `release_notes_${extensionVersion}`;

	if (workspaceContext.hasAnyFlutterProjects && !hasFlutterExtension && !shouldSuppress(installFlutterExtensionPromptKey))
		return showPrompt(installFlutterExtensionPromptKey, promptToInstallFlutterExtension);

	if (!isDevExtension && !shouldSuppress(releaseNotesKeyForThisVersion))
		return showPrompt(releaseNotesKeyForThisVersion, () => promptToShowReleaseNotes(extensionVersion, versionLink));
}

export async function showDevToolsNotificationIfAppropriate(context: Context): Promise<boolean> {
	const lastShown = context.devToolsNotificationLastShown;
	const timesShown = context.devToolsNotificationsShown;
	const doNotShow = context.devToolsNotificationDoNotShow;

	// Don't show this notification more than 10 times or if user said not to.
	if (doNotShow || timesShown >= 10)
		return false;

	// Don't show this notification if we've shown it in the last 20 hours.
	if (lastShown && Date.now() - lastShown < noRepeatPromptThreshold)
		return false;

	context.devToolsNotificationsShown++;
	context.devToolsNotificationLastShown = Date.now();

	const choice = await vs.window.showInformationMessage(wantToTryDevToolsPrompt, openDevToolsAction, noThanksAction, doNotAskAgainAction);
	if (choice === doNotAskAgainAction) {
		context.devToolsNotificationDoNotShow = true;
		return false;
	} else if (choice === openDevToolsAction) {
		vs.commands.executeCommand("dart.openDevTools");
		return true;
	} else {
		// No thanks.
		return false;
	}
}

async function promptToInstallFlutterExtension(): Promise<boolean> {
	const installExtension = "Install Flutter Extension";
	const res = await vs.window.showInformationMessage(
		"Working on a Flutter project? Install the Flutter extension for additional functionality.",
		installExtension,
		doNotAskAgainAction,
	);
	if (res === installExtension) {
		await vs.commands.executeCommand("workbench.extensions.installExtension", flutterExtensionIdentifier);
		reloadExtension();
	}
<commit_msg>Fix waiting for Flutter extension to install<commit_after>import * as fs from "fs";
import * as path from "path";
import * as vs from "vscode";
import { doNotAskAgainAction, noRepeatPromptThreshold, noThanksAction, openDevToolsAction, wantToTryDevToolsPrompt } from "./constants";
import { Context } from "./context";
import { flutterExtensionIdentifier } from "./debug/utils";
import { StagehandTemplate } from "./pub/stagehand";
import { DART_STAGEHAND_PROJECT_TRIGGER_FILE, extensionVersion, FLUTTER_CREATE_PROJECT_TRIGGER_FILE, FLUTTER_STAGEHAND_PROJECT_TRIGGER_FILE, fsPath, getDartWorkspaceFolders, hasFlutterExtension, isDevExtension, openInBrowser, reloadExtension, WorkspaceContext } from "./utils";

const promptPrefix = "hasPrompted.";
const installFlutterExtensionPromptKey = "install_flutter_extension_2";

export function showUserPrompts(context: Context, workspaceContext: WorkspaceContext): void {
	handleNewProjects(context);

	function shouldSuppress(key: string): boolean {
		const stateKey = `${promptPrefix}${key}`;
		return context.get(stateKey) === true;
	}

	/// Shows a prompt and stores the return value. Prompt should return `true` to mark
	/// this extension as seen-forever and it won't be shown again. Returning anything
	/// else will allow the prompt to appear again next time.
	function showPrompt(key: string, prompt: () => Thenable<boolean>): void {
		const stateKey = `${promptPrefix}${key}`;
		prompt().then((res) => context.update(stateKey, res), error);
	}

	const versionLink = extensionVersion.split(".").slice(0, 2).join(".").replace(".", "-");
	const releaseNotesKeyForThisVersion = `release_notes_${extensionVersion}`;

	if (workspaceContext.hasAnyFlutterProjects && !hasFlutterExtension && !shouldSuppress(installFlutterExtensionPromptKey))
		return showPrompt(installFlutterExtensionPromptKey, promptToInstallFlutterExtension);

	if (!isDevExtension && !shouldSuppress(releaseNotesKeyForThisVersion))
		return showPrompt(releaseNotesKeyForThisVersion, () => promptToShowReleaseNotes(extensionVersion, versionLink));
}

export async function showDevToolsNotificationIfAppropriate(context: Context): Promise<boolean> {
	const lastShown = context.devToolsNotificationLastShown;
	const timesShown = context.devToolsNotificationsShown;
	const doNotShow = context.devToolsNotificationDoNotShow;

	// Don't show this notification more than 10 times or if user said not to.
	if (doNotShow || timesShown >= 10)
		return false;

	// Don't show this notification if we've shown it in the last 20 hours.
	if (lastShown && Date.now() - lastShown < noRepeatPromptThreshold)
		return false;

	context.devToolsNotificationsShown++;
	context.devToolsNotificationLastShown = Date.now();

	const choice = await vs.window.showInformationMessage(wantToTryDevToolsPrompt, openDevToolsAction, noThanksAction, doNotAskAgainAction);
	if (choice === doNotAskAgainAction) {
		context.devToolsNotificationDoNotShow = true;
		return false;
	} else if (choice === openDevToolsAction) {
		vs.commands.executeCommand("dart.openDevTools");
		return true;
	} else {
		// No thanks.
		return false;
	}
}

async function promptToInstallFlutterExtension(): Promise<boolean> {
	const installExtension = "Install Flutter Extension";
	const res = await vs.window.showInformationMessage(
		"Working on a Flutter project? Install the Flutter extension for additional functionality.",
		installExtension,
		doNotAskAgainAction,
	);
	if (res === installExtension) {
		await vs.window.withProgress({ location: vs.ProgressLocation.Notification },
			(progress) => {
				progress.report({ message: "Installing Flutter extension" });

				return new Promise((resolve) => {
					vs.extensions.onDidChange((e) => resolve());
					vs.commands.executeCommand("workbench.extensions.installExtension", flutterExtensionIdentifier);
				});
			},
		);
		reloadExtension();
	}

{'fraction_non_alphanumeric': 0.10616254036598494, 'fraction_numerical': 0.0024219590958019376, 'mean_word_length': 6.22351797862002, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1506307', 'n_tokens_mistral': 2216, 'n_tokens_neox': 2098, 'n_words': 542}