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

import nls = require('vs/nls');
import { Promise, TPromise } from 'vs/base/common/winjs.base';
import actions = require('vs/base/common/actions');
import strings = require('vs/base/common/strings');
import URI from 'vs/base/common/uri';
import { isMacintosh, isLinux, isWindows } from 'vs/base/common/platform';
import actionbar = require('vs/base/browser/ui/actionbar/actionbar');
import dom = require('vs/base/browser/dom');
import errors = require('vs/base/common/errors');
import severity from 'vs/base/common/severity';
import mouse = require('vs/base/browser/mouseEvent');
import tree = require('vs/base/parts/tree/browser/tree');
import renderer = require('vs/base/parts/tree/browser/actionsRenderer');
import treedefaults = require('vs/base/parts/tree/browser/treeDefaults');
import debug = require('vs/workbench/parts/debug/common/debug');
import model = require('vs/workbench/parts/debug/common/debugModel');
import debugviewer = require('vs/workbench/parts/debug/browser/debugViewer');
import debugactions = require('vs/workbench/parts/debug/electron-browser/debugActions');
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';

const $ = dom.emmet;

function getExpressionClassName(): string {
	return isMacintosh ? '.expression.mac' : '.expression.win-linux'
}

export class ReplExpressionsDataSource implements tree.IDataSource {

	constructor(private debugService: debug.IDebugService) {
		// noop
	}

	public getId(tree: tree.ITree, element: any): string {
		return element.getId();
	}

	public hasChildren(tree: tree.ITree, element: any): boolean {
		return element instanceof model.Model || element.reference > 0  || (element instanceof model.KeyValueOutputElement && element.getChildren().length > 0);
	}

	public getChildren(tree: tree.ITree, element: any): Promise {
		if (element instanceof model.Model) {
			return Promise.as(element.getReplElements());
		}
		if (element instanceof model.KeyValueOutputElement) {
			return Promise.as(element.getChildren());
		}
		if (element instanceof model.ValueOutputElement) {
			return Promise.as(null);
		}

		return (<debug.IExpression> element).getChildren(this.debugService);
	}

	public getParent(tree: tree.ITree, element: any): Promise {
		return Promise.as(null);
	}
}

interface IInputOutputPairTemplateData {
	input: HTMLElement;
	output: HTMLElement;
	value: HTMLElement;
	annotation: HTMLElement;
}

interface IValueOutputTemplateData {
	container: HTMLElement;
	counter: HTMLElement;
	value: HTMLElement;
}

interface IKeyValueOutputTemplateData {
	container: HTMLElement;
	expression: HTMLElement;
	key: HTMLElement;
	value: HTMLElement;
	annotation: HTMLElement;
}

export class ReplExpressionsRenderer implements tree.IRenderer {

	private static VARIABLE_TEMPLATE_ID = 'variable';
	private static INPUT_OUTPUT_PAIR_TEMPLATE_ID = 'inputOutputPair';
	private static VALUE_OUTPUT_TEMPLATE_ID = 'outputValue';
	private static KEY_VALUE_OUTPUT_TEMPLATE_ID = 'outputKeyValue';

	private static FILE_LOCATION_PATTERNS: RegExp[] = [
		// group 0: the full thing :)
		// group 1: absolute path
		// group 2: drive letter on windows with trailing backslash or leading slash on mac/linux
		// group 3: line number
		// group 4: column number
		// eg: at Context.<anonymous> (c:\Users\someone\Desktop\mocha-runner\test\test.js:26:11)
		/((\/|[a-zA-Z]:\\)[^\(\)<>\'\"\[\]]+):(\d+):(\d+)/
	];

	private width: number;
	private characterWidth: number;

	constructor(
		@debug.IDebugService private debugService: debug.IDebugService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IWorkspaceContextService private contextService: IWorkspaceContextService
	) {
		// noop
	}

	public getHeight(tree: tree.ITree, element: any): number {
		return this.getHeightForString(element.value) + (element instanceof model.Expression ? this.getHeightForString(element.name) : 0);
	}

	private getHeightForString(s: string): number {
		if (!s || !s.length || this.width <= 0 || this.characterWidth <= 0) {
			return 18;
		}
		let realLength = 0;
		for (let i = 0; i < s.length; i++) {
			realLength += strings.isFullWidthCharacter(s.charCodeAt(i)) ? 2 : 1;
		}

		return 18 * Math.ceil(realLength * this.characterWidth / this.width);
	}

	public setWidth(fullWidth: number, characterWidth: number): void {
		this.width = fullWidth;
		this.characterWidth = characterWidth;
	}

	public getTemplateId(tree: tree.ITree, element: any): string {
		if (element instanceof model.Variable) {
			return ReplExpressionsRenderer.VARIABLE_TEMPLATE_ID;
		}
		if (element instanceof model.Expression) {
			return ReplExpressionsRenderer.INPUT_OUTPUT_PAIR_TEMPLATE_ID;
		}
		if (element instanceof model.ValueOutputElement) {<commit_msg>repl: give default element height when first output comes very early<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import nls = require('vs/nls');
import { Promise, TPromise } from 'vs/base/common/winjs.base';
import actions = require('vs/base/common/actions');
import strings = require('vs/base/common/strings');
import URI from 'vs/base/common/uri';
import { isMacintosh, isLinux, isWindows } from 'vs/base/common/platform';
import actionbar = require('vs/base/browser/ui/actionbar/actionbar');
import dom = require('vs/base/browser/dom');
import errors = require('vs/base/common/errors');
import severity from 'vs/base/common/severity';
import mouse = require('vs/base/browser/mouseEvent');
import tree = require('vs/base/parts/tree/browser/tree');
import renderer = require('vs/base/parts/tree/browser/actionsRenderer');
import treedefaults = require('vs/base/parts/tree/browser/treeDefaults');
import debug = require('vs/workbench/parts/debug/common/debug');
import model = require('vs/workbench/parts/debug/common/debugModel');
import debugviewer = require('vs/workbench/parts/debug/browser/debugViewer');
import debugactions = require('vs/workbench/parts/debug/electron-browser/debugActions');
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';

const $ = dom.emmet;

function getExpressionClassName(): string {
	return isMacintosh ? '.expression.mac' : '.expression.win-linux'
}

export class ReplExpressionsDataSource implements tree.IDataSource {

	constructor(private debugService: debug.IDebugService) {
		// noop
	}

	public getId(tree: tree.ITree, element: any): string {
		return element.getId();
	}

	public hasChildren(tree: tree.ITree, element: any): boolean {
		return element instanceof model.Model || element.reference > 0  || (element instanceof model.KeyValueOutputElement && element.getChildren().length > 0);
	}

	public getChildren(tree: tree.ITree, element: any): Promise {
		if (element instanceof model.Model) {
			return Promise.as(element.getReplElements());
		}
		if (element instanceof model.KeyValueOutputElement) {
			return Promise.as(element.getChildren());
		}
		if (element instanceof model.ValueOutputElement) {
			return Promise.as(null);
		}

		return (<debug.IExpression> element).getChildren(this.debugService);
	}

	public getParent(tree: tree.ITree, element: any): Promise {
		return Promise.as(null);
	}
}

interface IInputOutputPairTemplateData {
	input: HTMLElement;
	output: HTMLElement;
	value: HTMLElement;
	annotation: HTMLElement;
}

interface IValueOutputTemplateData {
	container: HTMLElement;
	counter: HTMLElement;
	value: HTMLElement;
}

interface IKeyValueOutputTemplateData {
	container: HTMLElement;
	expression: HTMLElement;
	key: HTMLElement;
	value: HTMLElement;
	annotation: HTMLElement;
}

export class ReplExpressionsRenderer implements tree.IRenderer {

	private static VARIABLE_TEMPLATE_ID = 'variable';
	private static INPUT_OUTPUT_PAIR_TEMPLATE_ID = 'inputOutputPair';
	private static VALUE_OUTPUT_TEMPLATE_ID = 'outputValue';
	private static KEY_VALUE_OUTPUT_TEMPLATE_ID = 'outputKeyValue';

	private static FILE_LOCATION_PATTERNS: RegExp[] = [
		// group 0: the full thing :)
		// group 1: absolute path
		// group 2: drive letter on windows with trailing backslash or leading slash on mac/linux
		// group 3: line number
		// group 4: column number
		// eg: at Context.<anonymous> (c:\Users\someone\Desktop\mocha-runner\test\test.js:26:11)
		/((\/|[a-zA-Z]:\\)[^\(\)<>\'\"\[\]]+):(\d+):(\d+)/
	];

	private width: number;
	private characterWidth: number;

	constructor(
		@debug.IDebugService private debugService: debug.IDebugService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IWorkspaceContextService private contextService: IWorkspaceContextService
	) {
		// noop
	}

	public getHeight(tree: tree.ITree, element: any): number {
		return this.getHeightForString(element.value) + (element instanceof model.Expression ? this.getHeightForString(element.name) : 0);
	}

	private getHeightForString(s: string): number {
		if (!s || !s.length || !this.width || this.width <= 0 || !this.characterWidth || this.characterWidth <= 0) {
			return 18;
		}
		let realLength = 0;
		for (let i = 0; i < s.length; i++) {
			realLength += strings.isFullWidthCharacter(s.charCodeAt(i)) ? 2 : 1;
		}

		return 18 * Math.ceil(realLength * this.characterWidth / this.width);
	}

	public setWidth(fullWidth: number, characterWidth: number): void {
		this.width = fullWidth;
		this.characterWidth = characterWidth;
	}

	public getTemplateId(tree: tree.ITree, element: any): string {
		if (element instanceof model.Variable) {
			return ReplExpressionsRenderer.VARIABLE_TEMPLATE_ID;
		}
		if (element instanceof model.Expression) {
			return ReplExpressionsRenderer.INPUT_OUTPUT_PAIR_TEMPLATE_ID;
		}
		if (element instanceof model.ValueOutputElement) {
{'fraction_non_alphanumeric': 0.15366845315098873, 'fraction_numerical': 0.004065791905377934, 'mean_word_length': 4.2411622276029055, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '3012639', 'n_tokens_mistral': 3356, 'n_tokens_neox': 3189, 'n_words': 742}