src/vs/editor/contrib/codeAction/codeActionCommands.ts/applyCodeAction
export async function applyCodeAction(
	accessor: ServicesAccessor,
	item: CodeActionItem,
	editor?: ICodeEditor,
): Promise<void> {
	const bulkEditService = accessor.get(IBulkEditService);
	const commandService = accessor.get(ICommandService);
	const telemetryService = accessor.get(ITelemetryService);
	const notificationService = accessor.get(INotificationService);

	type ApplyCodeActionEvent = {
		codeActionTitle: string;
		codeActionKind: string | undefined;
		codeActionIsPreferred: boolean;
	};
	type ApplyCodeEventClassification = {
		codeActionTitle: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
		codeActionKind: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
		codeActionIsPreferred: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
	};

	telemetryService.publicLog2<ApplyCodeActionEvent, ApplyCodeEventClassification>('codeAction.applyCodeAction', {
		codeActionTitle: item.action.title,
		codeActionKind: item.action.kind,
		codeActionIsPreferred: !!item.action.isPreferred,
	});

	await item.resolve(CancellationToken.None);

	if (item.action.edit) {
		await bulkEditService.apply(ResourceEdit.convert(item.action.edit), { editor, label: item.action.title });
	}

	if (item.action.command) {
		try {
			await commandService.executeCommand(item.action.command.id, ...(item.action.command.arguments || []));
		} catch (err) {
			const message = asMessage(err);
			notificationService.error(
				typeof message === 'string'
					? message
					: nls.localize('applyCodeActionFailed', "An unknown error occurred while applying the code action"));
		}
	}
}