<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 'vs/css!./codelens';
import {RunOnceScheduler, asWinJsPromise} from 'vs/base/common/async';
import {onUnexpectedError} from 'vs/base/common/errors';
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import Severity from 'vs/base/common/severity';
import {format} from 'vs/base/common/strings';
import {TPromise} from 'vs/base/common/winjs.base';
import * as dom from 'vs/base/browser/dom';
import {ICommandService} from 'vs/platform/commands/common/commands';
import {IMessageService} from 'vs/platform/message/common/message';
import {Range} from 'vs/editor/common/core/range';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {CodeLensProviderRegistry, ICodeLensSymbol, Command} from 'vs/editor/common/modes';
import {IModelService} from 'vs/editor/common/services/modelService';
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
import {editorContribution} from 'vs/editor/browser/editorBrowserExtensions';
import {ICodeLensData, getCodeLensData} from '../common/codelens';


class CodeLensViewZone implements editorBrowser.IViewZone {

	public afterLineNumber: number;
	public heightInLines: number;
	public suppressMouseDown: boolean;

	public domNode: HTMLElement;

	constructor(afterLineNumber: number) {

		this.afterLineNumber = afterLineNumber;
		this.heightInLines = 1;
		this.suppressMouseDown = true;

		this.domNode = document.createElement('div');
	}

	public setAfterLineNumber(afterLineNumber: number): void {
		this.afterLineNumber = afterLineNumber;
	}
}

class CodeLensContentWidget implements editorBrowser.IContentWidget {

	private static ID: number = 0;

	public suppressMouseDown: boolean;

	private _id: string;

	private _domNode: HTMLElement;
	private _subscription: IDisposable;
	private _symbolRange: Range;
	private _widgetPosition: editorBrowser.IContentWidgetPosition;
	private _editor: editorBrowser.ICodeEditor;
	private _commands: { [id: string]: Command } = Object.create(null);

	public constructor(editor: editorBrowser.ICodeEditor, symbolRange: Range,
		commandService: ICommandService, messageService: IMessageService) {

		this._id = 'codeLensWidget' + (++CodeLensContentWidget.ID);
		this._editor = editor;

		this.suppressMouseDown = true;

		this.setSymbolRange(symbolRange);

		this._domNode = document.createElement('span');
		this._domNode.style.height = `${editor.getConfiguration().lineHeight}px`;
		this._domNode.innerHTML = '&nbsp;';
		dom.addClass(this._domNode, 'codelens-decoration');
		dom.addClass(this._domNode, 'invisible-cl');
		this._subscription = dom.addDisposableListener(this._domNode, 'click', e => {
			let element = <HTMLElement>e.target;
			if (element.tagName === 'A' && element.id) {
				let command = this._commands[element.id];
				if (command) {
					editor.focus();
					commandService.executeCommand(command.id, ...command.arguments).done(undefined, err => {
						messageService.show(Severity.Error, err);
					});
				}
			}
		});

		this.updateVisibility();
	}

	public dispose(): void {
		this._subscription.dispose();
		this._symbolRange = null;
	}

	public updateVisibility(): void {
		if (this.isVisible()) {
			dom.removeClass(this._domNode, 'invisible-cl');
			dom.addClass(this._domNode, 'fadein');
		}
	}

	public withCommands(symbols: ICodeLensSymbol[]): void {
		this._commands = Object.create(null);
		if (!symbols || !symbols.length) {
			this._domNode.innerHTML = 'no commands';
			return;
		}

		let html: string[] = [];
		for (let i = 0; i < symbols.length; i++) {
			let command = symbols[i].command;
			let part: string;
			if (command.id) {
				part = format('<a id={0}>{1}</a>', i, command.title);
				this._commands[i] = command;
			} else {
				part = format('<span>{0}</span>', command.title);
			}
			html.push(part);
		}

		this._domNode.innerHTML = html.join('<span>&nbsp;|&nbsp;</span>');
		this._editor.layoutContentWidget(this);
	}

	public getId(): string {
		return this._id;
	}

	public getDomNode(): HTMLElement {
		return this._domNode;
	}

	public setSymbolRange(range: Range): void {<commit_msg>Escape command title for CodeLens<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 'vs/css!./codelens';
import {RunOnceScheduler, asWinJsPromise} from 'vs/base/common/async';
import {onUnexpectedError} from 'vs/base/common/errors';
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import Severity from 'vs/base/common/severity';
import {format, escape} from 'vs/base/common/strings';
import {TPromise} from 'vs/base/common/winjs.base';
import * as dom from 'vs/base/browser/dom';
import {ICommandService} from 'vs/platform/commands/common/commands';
import {IMessageService} from 'vs/platform/message/common/message';
import {Range} from 'vs/editor/common/core/range';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {CodeLensProviderRegistry, ICodeLensSymbol, Command} from 'vs/editor/common/modes';
import {IModelService} from 'vs/editor/common/services/modelService';
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
import {editorContribution} from 'vs/editor/browser/editorBrowserExtensions';
import {ICodeLensData, getCodeLensData} from '../common/codelens';


class CodeLensViewZone implements editorBrowser.IViewZone {

	public afterLineNumber: number;
	public heightInLines: number;
	public suppressMouseDown: boolean;

	public domNode: HTMLElement;

	constructor(afterLineNumber: number) {

		this.afterLineNumber = afterLineNumber;
		this.heightInLines = 1;
		this.suppressMouseDown = true;

		this.domNode = document.createElement('div');
	}

	public setAfterLineNumber(afterLineNumber: number): void {
		this.afterLineNumber = afterLineNumber;
	}
}

class CodeLensContentWidget implements editorBrowser.IContentWidget {

	private static ID: number = 0;

	public suppressMouseDown: boolean;

	private _id: string;

	private _domNode: HTMLElement;
	private _subscription: IDisposable;
	private _symbolRange: Range;
	private _widgetPosition: editorBrowser.IContentWidgetPosition;
	private _editor: editorBrowser.ICodeEditor;
	private _commands: { [id: string]: Command } = Object.create(null);

	public constructor(editor: editorBrowser.ICodeEditor, symbolRange: Range,
		commandService: ICommandService, messageService: IMessageService) {

		this._id = 'codeLensWidget' + (++CodeLensContentWidget.ID);
		this._editor = editor;

		this.suppressMouseDown = true;

		this.setSymbolRange(symbolRange);

		this._domNode = document.createElement('span');
		this._domNode.style.height = `${editor.getConfiguration().lineHeight}px`;
		this._domNode.innerHTML = '&nbsp;';
		dom.addClass(this._domNode, 'codelens-decoration');
		dom.addClass(this._domNode, 'invisible-cl');
		this._subscription = dom.addDisposableListener(this._domNode, 'click', e => {
			let element = <HTMLElement>e.target;
			if (element.tagName === 'A' && element.id) {
				let command = this._commands[element.id];
				if (command) {
					editor.focus();
					commandService.executeCommand(command.id, ...command.arguments).done(undefined, err => {
						messageService.show(Severity.Error, err);
					});
				}
			}
		});

		this.updateVisibility();
	}

	public dispose(): void {
		this._subscription.dispose();
		this._symbolRange = null;
	}

	public updateVisibility(): void {
		if (this.isVisible()) {
			dom.removeClass(this._domNode, 'invisible-cl');
			dom.addClass(this._domNode, 'fadein');
		}
	}

	public withCommands(symbols: ICodeLensSymbol[]): void {
		this._commands = Object.create(null);
		if (!symbols || !symbols.length) {
			this._domNode.innerHTML = 'no commands';
			return;
		}

		let html: string[] = [];
		for (let i = 0; i < symbols.length; i++) {
			let command = symbols[i].command;
			let title = escape(command.title);
			let part: string;
			if (command.id) {
				part = format('<a id={0}>{1}</a>', i, title);
				this._commands[i] = command;
			} else {
				part = format('<span>{0}</span>', title);
			}
			html.push(part);
		}

		this._domNode.innerHTML = html.join('<span>&nbsp;|&nbsp;</span>');
		this._editor.layoutContentWidget(this);
	}

	public getId(): string {
		return this._id;
	}

	public getDomNode(): HTMLElement {
		return this._domNode;
	}

	public setSymbolRange(range: Range): void {
{'fraction_non_alphanumeric': 0.17188198480107286, 'fraction_numerical': 0.0013410818059901655, 'mean_word_length': 3.868879216539717, 'pattern_counts': {'":': 0, '<': 19, '<?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': '7144584', 'n_tokens_mistral': 2915, 'n_tokens_neox': 2682, 'n_words': 590}