<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 { IDisposable } from 'vs/base/common/lifecycle';
import { Range } from 'vs/editor/common/core/range';
import { Position } from 'vs/editor/common/core/position';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { InlineDecoration, ViewModelDecoration, ICoordinatesConverter } from 'vs/editor/common/viewModel/viewModel';
import { IModelDecorationsChangedEvent } from 'vs/editor/common/model/textModelEvents';

export interface IDecorationsViewportData {
	/**
	 * decorations in the viewport.
	 */
	readonly decorations: ViewModelDecoration[];
	/**
	 * inline decorations grouped by each line in the viewport.
	 */
	readonly inlineDecorations: InlineDecoration[][];
}

export class ViewModelDecorations implements IDisposable {

	private readonly editorId: number;
	private readonly model: editorCommon.IModel;
	private readonly configuration: editorCommon.IConfiguration;
	private readonly _coordinatesConverter: ICoordinatesConverter;

	private _decorationsCache: { [decorationId: string]: ViewModelDecoration; };

	private _cachedModelDecorationsResolver: IDecorationsViewportData;
	private _cachedModelDecorationsResolverViewRange: Range;

	constructor(editorId: number, model: editorCommon.IModel, configuration: editorCommon.IConfiguration, coordinatesConverter: ICoordinatesConverter) {
		this.editorId = editorId;
		this.model = model;
		this.configuration = configuration;
		this._coordinatesConverter = coordinatesConverter;
		this._decorationsCache = Object.create(null);
		this._clearCachedModelDecorationsResolver();
	}

	private _clearCachedModelDecorationsResolver(): void {
		this._cachedModelDecorationsResolver = null;
		this._cachedModelDecorationsResolverViewRange = null;
	}

	public dispose(): void {
		this._decorationsCache = null;
		this._clearCachedModelDecorationsResolver();
	}

	public reset(): void {
		this._decorationsCache = Object.create(null);
		this._clearCachedModelDecorationsResolver();
	}

	public onModelDecorationsChanged(e: IModelDecorationsChangedEvent): void {
		let changedDecorations = e.changedDecorations;
		for (let i = 0, len = changedDecorations.length; i < len; i++) {
			let changedDecoration = changedDecorations[i];
			let myDecoration = this._decorationsCache[changedDecoration];
			if (!myDecoration) {
				continue;
			}

			myDecoration.range = null;
		}

		let removedDecorations = e.removedDecorations;
		for (let i = 0, len = removedDecorations.length; i < len; i++) {
			let removedDecoration = removedDecorations[i];
			delete this._decorationsCache[removedDecoration];
		}

		this._clearCachedModelDecorationsResolver();
	}

	public onLineMappingChanged(): void {
		this._decorationsCache = Object.create(null);

		this._clearCachedModelDecorationsResolver();
	}

	private _getOrCreateViewModelDecoration(modelDecoration: editorCommon.IModelDecoration): ViewModelDecoration {
		let id = modelDecoration.id;
		let r = this._decorationsCache[id];
		if (!r) {
			r = new ViewModelDecoration(modelDecoration);
			this._decorationsCache[id] = r;
		}
		if (r.range === null) {
			const modelRange = modelDecoration.range;
			if (modelDecoration.options.isWholeLine) {
				let start = this._coordinatesConverter.convertModelPositionToViewPosition(new Position(modelRange.startLineNumber, 1));
				let end = this._coordinatesConverter.convertModelPositionToViewPosition(new Position(modelRange.endLineNumber, this.model.getLineMaxColumn(modelRange.endLineNumber)));
				r.range = new Range(start.lineNumber, start.column, end.lineNumber, end.column);
			} else {
				r.range = this._coordinatesConverter.convertModelRangeToViewRange(modelRange);
			}<commit_msg>Fix #26106. Make sure arrary key is string<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 { IDisposable } from 'vs/base/common/lifecycle';
import { Range } from 'vs/editor/common/core/range';
import { Position } from 'vs/editor/common/core/position';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { InlineDecoration, ViewModelDecoration, ICoordinatesConverter } from 'vs/editor/common/viewModel/viewModel';
import { IModelDecorationsChangedEvent } from 'vs/editor/common/model/textModelEvents';

export interface IDecorationsViewportData {
	/**
	 * decorations in the viewport.
	 */
	readonly decorations: ViewModelDecoration[];
	/**
	 * inline decorations grouped by each line in the viewport.
	 */
	readonly inlineDecorations: InlineDecoration[][];
}

export class ViewModelDecorations implements IDisposable {

	private readonly editorId: number;
	private readonly model: editorCommon.IModel;
	private readonly configuration: editorCommon.IConfiguration;
	private readonly _coordinatesConverter: ICoordinatesConverter;

	private _decorationsCache: { [decorationId: string]: ViewModelDecoration; };

	private _cachedModelDecorationsResolver: IDecorationsViewportData;
	private _cachedModelDecorationsResolverViewRange: Range;

	constructor(editorId: number, model: editorCommon.IModel, configuration: editorCommon.IConfiguration, coordinatesConverter: ICoordinatesConverter) {
		this.editorId = editorId;
		this.model = model;
		this.configuration = configuration;
		this._coordinatesConverter = coordinatesConverter;
		this._decorationsCache = Object.create(null);
		this._clearCachedModelDecorationsResolver();
	}

	private _clearCachedModelDecorationsResolver(): void {
		this._cachedModelDecorationsResolver = null;
		this._cachedModelDecorationsResolverViewRange = null;
	}

	public dispose(): void {
		this._decorationsCache = null;
		this._clearCachedModelDecorationsResolver();
	}

	public reset(): void {
		this._decorationsCache = Object.create(null);
		this._clearCachedModelDecorationsResolver();
	}

	public onModelDecorationsChanged(e: IModelDecorationsChangedEvent): void {
		let changedDecorations = e.changedDecorations;
		for (let i = 0, len = changedDecorations.length; i < len; i++) {
			let changedDecoration = changedDecorations[i];
			let myDecoration = this._decorationsCache[changedDecoration];
			if (!myDecoration) {
				continue;
			}

			myDecoration.range = null;
		}

		let removedDecorations = e.removedDecorations;
		for (let i = 0, len = removedDecorations.length; i < len; i++) {
			let removedDecoration = removedDecorations[i];
			if (removedDecoration !== null && removedDecoration !== undefined) {
				delete this._decorationsCache[removedDecoration];
			}
		}

		this._clearCachedModelDecorationsResolver();
	}

	public onLineMappingChanged(): void {
		this._decorationsCache = Object.create(null);

		this._clearCachedModelDecorationsResolver();
	}

	private _getOrCreateViewModelDecoration(modelDecoration: editorCommon.IModelDecoration): ViewModelDecoration {
		let id = modelDecoration.id;
		let r = this._decorationsCache[id];
		if (!r) {
			r = new ViewModelDecoration(modelDecoration);
			this._decorationsCache[id] = r;
		}
		if (r.range === null) {
			const modelRange = modelDecoration.range;
			if (modelDecoration.options.isWholeLine) {
				let start = this._coordinatesConverter.convertModelPositionToViewPosition(new Position(modelRange.startLineNumber, 1));
				let end = this._coordinatesConverter.convertModelPositionToViewPosition(new Position(modelRange.endLineNumber, this.model.getLineMaxColumn(modelRange.endLineNumber)));
				r.range = new Range(start.lineNumber, start.column, end.lineNumber, end.column);
			} else {
				r.range = this._coordinatesConverter.convertModelRangeToViewRange(modelRange);
			}
{'fraction_non_alphanumeric': 0.137449467107681, 'fraction_numerical': 0.001347543795173343, 'mean_word_length': 4.287564766839378, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '4888525', 'n_tokens_mistral': 2418, 'n_tokens_neox': 2219, 'n_words': 488}