src/vs/workbench/contrib/terminal/browser/xterm/quickFixAddon.ts/getQuickFixesForCommand
export async function getQuickFixesForCommand(
	aliases: string[][] | undefined,
	terminal: Terminal,
	terminalCommand: ITerminalCommand,
	quickFixOptions: Map<string, ITerminalQuickFixOptions[]>,
	openerService: IOpenerService,
	onDidRequestRerunCommand?: Emitter<{ command: string; addNewLine?: boolean }>,
	getResolvedFixes?: (selector: ITerminalQuickFixOptions, lines?: string[]) => Promise<ITerminalQuickFix | ITerminalQuickFix[] | undefined>
): Promise<ITerminalAction[] | undefined> {
	const fixes: ITerminalAction[] = [];
	const newCommand = terminalCommand.command;
	const expectedCommands = [];
	for (const options of quickFixOptions.values()) {
		for (const option of options) {
			if (option.exitStatus === (terminalCommand.exitCode !== 0)) {
				continue;
			}
			let quickFixes;
			if (option.type === 'resolved') {
				quickFixes = await (option as IResolvedExtensionOptions).getQuickFixes(terminalCommand, getLinesForCommand(terminal.buffer.active, terminalCommand, terminal.cols, option.outputMatcher), option, new CancellationTokenSource().token);
			} else if (option.type === 'unresolved') {
				if (!getResolvedFixes) {
					throw new Error('No resolved fix provider');
				}
				quickFixes = await getResolvedFixes(option, option.outputMatcher ? getLinesForCommand(terminal.buffer.active, terminalCommand, terminal.cols, option.outputMatcher) : undefined);
			} else if (option.type === 'internal') {
				const commandLineMatch = newCommand.match(option.commandLineMatcher);
				if (!commandLineMatch) {
					continue;
				}
				const outputMatcher = option.outputMatcher;
				let outputMatch;
				if (outputMatcher) {
					outputMatch = terminalCommand.getOutputMatch(outputMatcher);
				}
				if (!outputMatch) {
					continue;
				}
				const matchResult = { commandLineMatch, outputMatch, commandLine: terminalCommand.command };
				quickFixes = (option as IInternalOptions).getQuickFixes(matchResult);
			}

			if (quickFixes) {
				for (const quickFix of asArray(quickFixes)) {
					let action: ITerminalAction | undefined;
					if ('type' in quickFix) {
						switch (quickFix.type) {
							case TerminalQuickFixType.Command: {
								const fix = quickFix as ITerminalQuickFixCommandAction;
								const label = localize('quickFix.command', 'Run: {0}', fix.terminalCommand);
								action = {
									source: quickFix.source,
									id: quickFix.id,
									label,
									class: quickFix.type,
									enabled: true,
									run: () => {
										onDidRequestRerunCommand?.fire({
											command: fix.terminalCommand,
											addNewLine: fix.addNewLine
										});
									},
									tooltip: label,
									command: fix.terminalCommand
								} as ITerminalAction;
								expectedCommands.push(fix.terminalCommand);
								break;
							}
							case TerminalQuickFixType.Opener: {
								const fix = quickFix as ITerminalQuickFixOpenerAction;
								const label = localize('quickFix.opener', 'Open: {0}', fix.uri.toString());
								action = {
									source: quickFix.source,
									id: quickFix.id,
									label,
									class: quickFix.type,
									enabled: true,
									run: () => {
										let uri: URI | undefined;
										if (URI.isUri(fix.uri)) {
											uri = fix.uri;
										} else if (typeof fix.uri === 'string') {
											uri = URI.parse(fix.uri);
										}

										if (!uri) {
											return;
										}
										openerService.open(uri);
									},
									tooltip: label,
									uri: fix.uri
								} as ITerminalAction;
								break;
							}
						}
					} else {
						const fix = quickFix as ITerminalAction;
						action = {
							source: 'builtin',
							id: fix.id,
							label: fix.label,
							class: fix.class,
							enabled: fix.enabled,
							run: () => {
								fix.run();
							},
							tooltip: fix.tooltip
						};
					}
					if (action) {
						fixes.push(action);
					}
				}
			}
		}
	}
	return fixes.length > 0 ? fixes : undefined;
}