<commit_before>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

import { MainContext, MainThreadOutputServiceShape, IMainContext } from './extHost.protocol';
import * as vscode from 'vscode';
import { URI } from 'vs/base/common/uri';
import { posix } from 'path';
import { OutputAppender } from 'vs/platform/output/node/outputAppender';
import { toLocalISOString } from 'vs/base/common/date';

export abstract class AbstractExtHostOutputChannel implements vscode.OutputChannel {

	protected readonly _id: Thenable<string>;
	private readonly _name: string;
	protected readonly _proxy: MainThreadOutputServiceShape;
	private _disposed: boolean;

	constructor(name: string, file: URI, proxy: MainThreadOutputServiceShape) {
		this._name = name;
		this._proxy = proxy;
		this._id = proxy.$register(this.name, file);
	}

	get name(): string {
		return this._name;
	}

	abstract append(value: string): void;

	appendLine(value: string): void {
		this.validate();
		this.append(value + '\n');
	}

	clear(): void {
		this.validate();
		this._id.then(id => this._proxy.$clear(id));
	}

	show(columnOrPreserveFocus?: vscode.ViewColumn | boolean, preserveFocus?: boolean): void {
		this.validate();
		this._id.then(id => this._proxy.$reveal(id, typeof columnOrPreserveFocus === 'boolean' ? columnOrPreserveFocus : preserveFocus));
	}

	hide(): void {
		this.validate();
		this._id.then(id => this._proxy.$close(id));
	}

	protected validate(): void {
		if (this._disposed) {
			throw new Error('Channel has been closed');
		}
	}

	dispose(): void {
		if (!this._disposed) {
			this._id
				.then(id => this._proxy.$dispose(id))
				.then(() => this._disposed = true);
		}
	}
}

export class ExtHostPushOutputChannel extends AbstractExtHostOutputChannel {

	constructor(name: string, proxy: MainThreadOutputServiceShape) {
		super(name, null, proxy);
	}

	append(value: string): void {
		this.validate();
		this._id.then(id => this._proxy.$append(id, value));
	}
}

export class ExtHostPullOutputChannel extends AbstractExtHostOutputChannel {

	private static _namePool = 1;
	private _appender: OutputAppender;

	constructor(name: string, outputDir: string, proxy: MainThreadOutputServiceShape) {
		const fileName = `${ExtHostPullOutputChannel._namePool++}-${name}`;
		const file = URI.file(posix.join(outputDir, `${fileName}.log`));

		super(name, file, proxy);
		this._appender = new OutputAppender(fileName, file.fsPath);
	}

	append(value: string): void {
		this.validate();
		this._appender.append(value);
	}
}

export class ExtHostOutputService {

	private _proxy: MainThreadOutputServiceShape;
	private _outputDir: string;

	constructor(logsLocation: URI, mainContext: IMainContext) {
		this._outputDir = posix.join(logsLocation.fsPath, `output_logging_${toLocalISOString(new Date()).replace(/-|:|\.\d+Z$/g, '')}`);
		this._proxy = mainContext.getProxy(MainContext.MainThreadOutputService);
	}

	createOutputChannel(name: string, push: boolean): vscode.OutputChannel {
		name = name.trim();
		if (!name) {
			throw new Error('illegal argument `name`. must not be falsy');
		} else {
			return push ? new ExtHostPushOutputChannel(name, this._proxy) : new ExtHostPullOutputChannel(name, this._outputDir, this._proxy);
		}
	}
}
<commit_msg>:lipstick:<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

import { MainContext, MainThreadOutputServiceShape, IMainContext } from './extHost.protocol';
import * as vscode from 'vscode';
import { URI } from 'vs/base/common/uri';
import { posix } from 'path';
import { OutputAppender } from 'vs/platform/output/node/outputAppender';
import { toLocalISOString } from 'vs/base/common/date';

export abstract class AbstractExtHostOutputChannel implements vscode.OutputChannel {

	protected readonly _id: Thenable<string>;
	private readonly _name: string;
	protected readonly _proxy: MainThreadOutputServiceShape;
	private _disposed: boolean;

	constructor(name: string, file: URI, proxy: MainThreadOutputServiceShape) {
		this._name = name;
		this._proxy = proxy;
		this._id = proxy.$register(this.name, file);
	}

	get name(): string {
		return this._name;
	}

	abstract append(value: string): void;

	appendLine(value: string): void {
		this.validate();
		this.append(value + '\n');
	}

	clear(): void {
		this.validate();
		this._id.then(id => this._proxy.$clear(id));
	}

	show(columnOrPreserveFocus?: vscode.ViewColumn | boolean, preserveFocus?: boolean): void {
		this.validate();
		this._id.then(id => this._proxy.$reveal(id, typeof columnOrPreserveFocus === 'boolean' ? columnOrPreserveFocus : preserveFocus));
	}

	hide(): void {
		this.validate();
		this._id.then(id => this._proxy.$close(id));
	}

	protected validate(): void {
		if (this._disposed) {
			throw new Error('Channel has been closed');
		}
	}

	dispose(): void {
		if (!this._disposed) {
			this._id
				.then(id => this._proxy.$dispose(id))
				.then(() => this._disposed = true);
		}
	}
}

export class ExtHostPushOutputChannel extends AbstractExtHostOutputChannel {

	constructor(name: string, proxy: MainThreadOutputServiceShape) {
		super(name, null, proxy);
	}

	append(value: string): void {
		this.validate();
		this._id.then(id => this._proxy.$append(id, value));
	}
}

export class ExtHostFileOutputChannel extends AbstractExtHostOutputChannel {

	private static _namePool = 1;
	private _appender: OutputAppender;

	constructor(name: string, outputDir: string, proxy: MainThreadOutputServiceShape) {
		const fileName = `${ExtHostFileOutputChannel._namePool++}-${name}`;
		const file = URI.file(posix.join(outputDir, `${fileName}.log`));

		super(name, file, proxy);
		this._appender = new OutputAppender(fileName, file.fsPath);
	}

	append(value: string): void {
		this.validate();
		this._appender.append(value);
	}
}

export class ExtHostOutputService {

	private _proxy: MainThreadOutputServiceShape;
	private _outputDir: string;

	constructor(logsLocation: URI, mainContext: IMainContext) {
		this._outputDir = posix.join(logsLocation.fsPath, `output_logging_${toLocalISOString(new Date()).replace(/-|:|\.\d+Z$/g, '')}`);
		this._proxy = mainContext.getProxy(MainContext.MainThreadOutputService);
	}

	createOutputChannel(name: string, push: boolean): vscode.OutputChannel {
		name = name.trim();
		if (!name) {
			throw new Error('illegal argument `name`. must not be falsy');
		} else {
			return push ? new ExtHostPushOutputChannel(name, this._proxy) : new ExtHostFileOutputChannel(name, this._outputDir, this._proxy);
		}
	}
}

{'fraction_non_alphanumeric': 0.1820487529942229, 'fraction_numerical': 0.0002818092151613358, 'mean_word_length': 3.7162790697674417, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '6882300', 'n_tokens_mistral': 2221, 'n_tokens_neox': 2098, 'n_words': 496}