<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 'vs/css!vs/workbench/parts/debug/browser/media/repl';
import * as nls from 'vs/nls';
import { URI as uri } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import * as errors from 'vs/base/common/errors';
import { IAction, IActionItem } from 'vs/base/common/actions';
import * as dom from 'vs/base/browser/dom';
import * as aria from 'vs/base/browser/ui/aria/aria';
import { isMacintosh } from 'vs/base/common/platform';
import { CancellationToken } from 'vs/base/common/cancellation';
import { KeyCode } from 'vs/base/common/keyCodes';
import { ITree, ITreeOptions } from 'vs/base/parts/tree/browser/tree';
import { Context as SuggestContext } from 'vs/editor/contrib/suggest/suggest';
import { SuggestController } from 'vs/editor/contrib/suggest/suggestController';
import { ITextModel } from 'vs/editor/common/model';
import { Position } from 'vs/editor/common/core/position';
import * as modes from 'vs/editor/common/modes';
import { registerEditorAction, ServicesAccessor, EditorAction, EditorCommand, registerEditorCommand } from 'vs/editor/browser/editorExtensions';
import { IModelService } from 'vs/editor/common/services/modelService';
import { MenuId } from 'vs/platform/actions/common/actions';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { IContextKeyService, ContextKeyExpr, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IInstantiationService, createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { ReplExpressionsRenderer, ReplExpressionsController, ReplExpressionsDataSource, ReplExpressionsActionProvider, ReplExpressionsAccessibilityProvider } from 'vs/workbench/parts/debug/electron-browser/replViewer';
import { ClearReplAction, FocusSessionAction } from 'vs/workbench/parts/debug/browser/debugActions';
import { Panel } from 'vs/workbench/browser/panel';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { clipboard } from 'electron';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { WorkbenchTree } from 'vs/platform/list/browser/listService';
import { memoize } from 'vs/base/common/decorators';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { OpenMode, ClickBehavior } from 'vs/base/parts/tree/browser/treeDefaults';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { IDebugService, REPL_ID, DEBUG_SCHEME, CONTEXT_IN_DEBUG_REPL } from 'vs/workbench/parts/debug/common/debug';
import { HistoryNavigator } from 'vs/base/common/history';
import { IHistoryNavigationWidget } from 'vs/base/browser/history';
import { createAndBindHistoryNavigationWidgetScopedContextKeyService } from 'vs/platform/widget/browser/contextScopedHistoryWidget';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { getSimpleCodeEditorWidgetOptions } from 'vs/workbench/parts/codeEditor/electron-browser/simpleEditorOptions';
import { getSimpleEditorOptions } from 'vs/workbench/parts/codeEditor/browser/simpleEditorOptions';
import { IDecorationOptions } from 'vs/editor/common/editorCommon';
import { transparent, editorForeground } from 'vs/platform/theme/common/colorRegistry';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { FocusSessionActionItem } from 'vs/workbench/parts/debug/browser/debugActionItems';

const $ = dom.$;

const replTreeOptions: ITreeOptions = {
	twistiePixels: 20,
	ariaLabel: nls.localize('replAriaLabel', "Read Eval Print Loop Panel")
};

const HISTORY_STORAGE_KEY = 'debug.repl.history';
const IPrivateReplService = createDecorator<IPrivateReplService>('privateReplService');
const DECORATION_KEY = 'replinputdecoration';

export interface IPrivateReplService {
	_serviceBrand: any;
	acceptReplInput(): void;
	getVisibleContent(): string;
}

export class Repl extends Panel implements IPrivateReplService, IHistoryNavigationWidget {
	public _serviceBrand: any;

	private static readonly HALF_WIDTH_TYPICAL = 'n';

	private history: HistoryNavigator<string>;
	private static readonly REFRESH_DELAY = 500; // delay in ms to refresh the repl for new elements to show
	private static readonly REPL_INPUT_INITIAL_HEIGHT = 19;
	private static readonly REPL_INPUT_MAX_HEIGHT = 170;

	private tree: ITree;
	private renderer: ReplExpressionsRenderer;
	private container: HTMLElement;
	private treeContainer: HTMLElement;
	private replInput: CodeEditorWidget;
	private replInputContainer: HTMLElement;
	private refreshTimeoutHandle: any;
	private dimension: dom.Dimension;
	private replInputHeight: number;
	private model: ITextModel;
	private historyNavigationEnablement: IContextKey<boolean>;

	constructor(
		@IDebugService private debugService: IDebugService,
		@ITelemetryService telemetryService: ITelemetryService,
		@IInstantiationService private instantiationService: IInstantiationService,
		@IStorageService private storageService: IStorageService,
		@IPanelService private panelService: IPanelService,
		@IThemeService protected themeService: IThemeService,
		@IModelService private modelService: IModelService,
		@IContextKeyService private contextKeyService: IContextKeyService,
		@ICodeEditorService codeEditorService: ICodeEditorService,
	) {
		super(REPL_ID, telemetryService, themeService);

		this.replInputHeight = Repl.REPL_INPUT_INITIAL_HEIGHT;
		this.history = new HistoryNavigator(JSON.parse(this.storageService.get(HISTORY_STORAGE_KEY, StorageScope.WORKSPACE, '[]')), 50);
		this.registerListeners();
		codeEditorService.registerDecorationType(DECORATION_KEY, {});
	}

	private registerListeners(): void {
		let replElementsChangeListener: IDisposable;
		this._register(this.debugService.getViewModel().onDidFocusSession(session => {
			if (replElementsChangeListener) {
				replElementsChangeListener.dispose();
			}
			if (session) {
				replElementsChangeListener = session.onDidChangeReplElements(() => {
					this.refreshReplElements(session.getReplElements().length === 0);
				});

				if (this.tree && this.isVisible()) {
					this.tree.setInput(session);
				}
			}
			this.replInput.updateOptions({ readOnly: !session });
			if (this.isVisible()) {
				this.updateInputDecoration();
			}
		}));
		this._register(this.panelService.onDidPanelOpen(panel => this.refreshReplElements(true)));
		this._register(this.debugService.onDidNewSession(() => this.updateTitleArea()));
		this._register(this.debugService.onDidEndSession(() => {
			if (this.debugService.getModel().getSessions().length === 0 && this.isVisible()) {
				// Only hide the session drop down when there are 0 sessions
				this.updateTitleArea();
			}
		}));
		this._register(this.themeService.onThemeChange(() => {
			if (this.isVisible()) {
				this.updateInputDecoration();
			}<commit_msg>repl: minor fix<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 'vs/css!vs/workbench/parts/debug/browser/media/repl';
import * as nls from 'vs/nls';
import { URI as uri } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import * as errors from 'vs/base/common/errors';
import { IAction, IActionItem } from 'vs/base/common/actions';
import * as dom from 'vs/base/browser/dom';
import * as aria from 'vs/base/browser/ui/aria/aria';
import { isMacintosh } from 'vs/base/common/platform';
import { CancellationToken } from 'vs/base/common/cancellation';
import { KeyCode } from 'vs/base/common/keyCodes';
import { ITree, ITreeOptions } from 'vs/base/parts/tree/browser/tree';
import { Context as SuggestContext } from 'vs/editor/contrib/suggest/suggest';
import { SuggestController } from 'vs/editor/contrib/suggest/suggestController';
import { ITextModel } from 'vs/editor/common/model';
import { Position } from 'vs/editor/common/core/position';
import * as modes from 'vs/editor/common/modes';
import { registerEditorAction, ServicesAccessor, EditorAction, EditorCommand, registerEditorCommand } from 'vs/editor/browser/editorExtensions';
import { IModelService } from 'vs/editor/common/services/modelService';
import { MenuId } from 'vs/platform/actions/common/actions';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { IContextKeyService, ContextKeyExpr, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IInstantiationService, createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { ReplExpressionsRenderer, ReplExpressionsController, ReplExpressionsDataSource, ReplExpressionsActionProvider, ReplExpressionsAccessibilityProvider } from 'vs/workbench/parts/debug/electron-browser/replViewer';
import { ClearReplAction, FocusSessionAction } from 'vs/workbench/parts/debug/browser/debugActions';
import { Panel } from 'vs/workbench/browser/panel';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { clipboard } from 'electron';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { WorkbenchTree } from 'vs/platform/list/browser/listService';
import { memoize } from 'vs/base/common/decorators';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { OpenMode, ClickBehavior } from 'vs/base/parts/tree/browser/treeDefaults';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { IDebugService, REPL_ID, DEBUG_SCHEME, CONTEXT_IN_DEBUG_REPL } from 'vs/workbench/parts/debug/common/debug';
import { HistoryNavigator } from 'vs/base/common/history';
import { IHistoryNavigationWidget } from 'vs/base/browser/history';
import { createAndBindHistoryNavigationWidgetScopedContextKeyService } from 'vs/platform/widget/browser/contextScopedHistoryWidget';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { getSimpleCodeEditorWidgetOptions } from 'vs/workbench/parts/codeEditor/electron-browser/simpleEditorOptions';
import { getSimpleEditorOptions } from 'vs/workbench/parts/codeEditor/browser/simpleEditorOptions';
import { IDecorationOptions } from 'vs/editor/common/editorCommon';
import { transparent, editorForeground } from 'vs/platform/theme/common/colorRegistry';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { FocusSessionActionItem } from 'vs/workbench/parts/debug/browser/debugActionItems';

const $ = dom.$;

const replTreeOptions: ITreeOptions = {
	twistiePixels: 20,
	ariaLabel: nls.localize('replAriaLabel', "Read Eval Print Loop Panel")
};

const HISTORY_STORAGE_KEY = 'debug.repl.history';
const IPrivateReplService = createDecorator<IPrivateReplService>('privateReplService');
const DECORATION_KEY = 'replinputdecoration';

export interface IPrivateReplService {
	_serviceBrand: any;
	acceptReplInput(): void;
	getVisibleContent(): string;
}

export class Repl extends Panel implements IPrivateReplService, IHistoryNavigationWidget {
	public _serviceBrand: any;

	private static readonly HALF_WIDTH_TYPICAL = 'n';

	private history: HistoryNavigator<string>;
	private static readonly REFRESH_DELAY = 500; // delay in ms to refresh the repl for new elements to show
	private static readonly REPL_INPUT_INITIAL_HEIGHT = 19;
	private static readonly REPL_INPUT_MAX_HEIGHT = 170;

	private tree: ITree;
	private renderer: ReplExpressionsRenderer;
	private container: HTMLElement;
	private treeContainer: HTMLElement;
	private replInput: CodeEditorWidget;
	private replInputContainer: HTMLElement;
	private refreshTimeoutHandle: any;
	private dimension: dom.Dimension;
	private replInputHeight: number;
	private model: ITextModel;
	private historyNavigationEnablement: IContextKey<boolean>;

	constructor(
		@IDebugService private debugService: IDebugService,
		@ITelemetryService telemetryService: ITelemetryService,
		@IInstantiationService private instantiationService: IInstantiationService,
		@IStorageService private storageService: IStorageService,
		@IPanelService private panelService: IPanelService,
		@IThemeService protected themeService: IThemeService,
		@IModelService private modelService: IModelService,
		@IContextKeyService private contextKeyService: IContextKeyService,
		@ICodeEditorService codeEditorService: ICodeEditorService,
	) {
		super(REPL_ID, telemetryService, themeService);

		this.replInputHeight = Repl.REPL_INPUT_INITIAL_HEIGHT;
		this.history = new HistoryNavigator(JSON.parse(this.storageService.get(HISTORY_STORAGE_KEY, StorageScope.WORKSPACE, '[]')), 50);
		this.registerListeners();
		codeEditorService.registerDecorationType(DECORATION_KEY, {});
	}

	private registerListeners(): void {
		let replElementsChangeListener: IDisposable;
		this._register(this.debugService.getViewModel().onDidFocusSession(session => {
			if (replElementsChangeListener) {
				replElementsChangeListener.dispose();
			}
			if (session) {
				replElementsChangeListener = session.onDidChangeReplElements(() => {
					this.refreshReplElements(session.getReplElements().length === 0);
				});

				if (this.tree && this.isVisible()) {
					this.tree.setInput(session);
				}
			}
			this.replInput.updateOptions({ readOnly: !session });
			if (this.isVisible()) {
				this.updateInputDecoration();
			}
		}));
		this._register(this.panelService.onDidPanelOpen(panel => this.refreshReplElements(true)));
		this._register(this.debugService.onDidNewSession(() => this.updateTitleArea()));
		this._register(this.debugService.onDidEndSession(() => {
			if (this.debugService.getModel().getSessions().length === 0) {
				// Only hide the session drop down when there are 0 sessions
				this.updateTitleArea();
			}
		}));
		this._register(this.themeService.onThemeChange(() => {
			if (this.isVisible()) {
				this.updateInputDecoration();
			}
{'fraction_non_alphanumeric': 0.13187981919702207, 'fraction_numerical': 0.0019941504918904547, 'mean_word_length': 5.237562189054726, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, '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': '5320991', 'n_tokens_mistral': 4464, 'n_tokens_neox': 4250, 'n_words': 911}