<commit_before>'use strict';

import * as vscode from 'vscode';
import * as child_process from 'child_process';
import * as path from 'path';

interface ShellCommand {
    description: string,
    command: string;
}

export function activate(context: vscode.ExtensionContext) {
	console.log('StartAnyShell is now active.');

	const startShell = vscode.commands.registerCommand("startanyshell.startShell", () => {
		let rootPath = vscode.workspace.rootPath;
		
		// TODO: option to open at workspace level or file level
		if (!rootPath) {
			let editor = vscode.window.activeTextEditor;
			if (editor && editor.document && editor.document.uri) {
				rootPath = path.dirname(editor.document.uri.fsPath);
			}
		};
	
		if (!rootPath || rootPath == "") rootPath = ".";
		
		let options: vscode.QuickPickOptions = { matchOnDescription: false, placeHolder: "Launch any shell in: " + rootPath };

		Promise.resolve(vscode.window.showQuickPick(getShells(context), options))
			.then((item) => {
				if (!item) return;
				if (!item.shell) return;

				child_process.exec(formatCommand(item.shell.command, rootPath, context));
			});
	});

	context.subscriptions.push(startShell);
}

function getShells(context: vscode.ExtensionContext) {
	let section = vscode.workspace.getConfiguration('startanyshell');
	let shells: ShellCommand[] = section.get<ShellCommand[]>("shells", []);

	return shells.map(shell => {
		return { label: shell.description, description: shell.command, context, shell: shell };
	});
}

function formatCommand(command: string, rootPath: string, context: vscode.ExtensionContext) {
	return command
		.replace('%path%', rootPath);
	// TODO: add more tokens or eval();
}<commit_msg>Refactor / clean up<commit_after>'use strict';

import {window, workspace, commands, ExtensionContext, QuickPickItem, QuickPickOptions} from 'vscode';
import * as child_process from 'child_process';
import * as path from 'path';

interface ShellCommand {
    description: string,
    command: string;
}

interface ShellQuickPickItem extends QuickPickItem {
    shell: ShellCommand
}

export function activate(context: ExtensionContext) {
    console.log('StartAnyShell is now active.');

    const startShell = commands.registerCommand("startanyshell.startShell", () => {
        let rootPath = workspace.rootPath;
		
        // TODO: option to open at workspace level or file level
        if (!rootPath) {
            let editor = window.activeTextEditor;
            if (editor && editor.document && editor.document.uri) {
                rootPath = path.dirname(editor.document.uri.fsPath);
            }
        };

        if (!rootPath || rootPath == "") rootPath = ".";

        let options: QuickPickOptions = { matchOnDescription: false, placeHolder: "Launch any shell in: " + rootPath };

        Promise.resolve(window.showQuickPick(getShells(context), options))
            .then((item) => {
                if (!item) return;
                if (!item.shell) return;

                child_process.exec(formatCommand(item.shell.command, rootPath, context));
            })
            .catch(error => {
                window.showErrorMessage(error.message || error);
            });
    });

    context.subscriptions.push(startShell);
}

function getShells(context: ExtensionContext): Promise<ShellQuickPickItem[]> {
    return new Promise(resolve=> {
        let section = workspace.getConfiguration('startanyshell');
        let shells: ShellCommand[] = section.get<ShellCommand[]>("shells", []);

        resolve(shells.map(shell => {
            return { label: shell.description, description: shell.command, context, shell: shell };
        }));
    });
}

function formatCommand(command: string, rootPath: string, context: ExtensionContext) {
    return command
        .replace('%path%', rootPath);
    // TODO: add more tokens or eval();
}
{'fraction_non_alphanumeric': 0.12947586922677737, 'fraction_numerical': 0.0, 'mean_word_length': 3.466975666280417, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 14, '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': '5032512', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1070, 'n_words': 264}