<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 { ThrottledDelayer } from 'vs/base/common/async';
import * as lifecycle from 'vs/base/common/lifecycle';
import * as winjs from 'vs/base/common/winjs.base';
import { memoize } from 'vs/base/common/decorators';
import * as ext from 'vs/workbench/common/contributions';
import * as common from 'vs/editor/common/editorCommon';
import * as widget from 'vs/editor/browser/codeEditor';
import { IEventService } from 'vs/platform/event/common/event';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IMessageService } from 'vs/platform/message/common/message';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { ITextModelResolverService } from 'vs/editor/common/services/resolverService';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import URI from 'vs/base/common/uri';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { ISCMService } from 'vs/workbench/services/scm/common/scm';

class DirtyDiffModelDecorator {

	static MODIFIED_DECORATION_OPTIONS: common.IModelDecorationOptions = {
		linesDecorationsClassName: 'git-dirty-modified-diff-glyph',
		isWholeLine: true,
		overviewRuler: {
			color: 'rgba(0, 122, 204, 0.6)',
			darkColor: 'rgba(0, 122, 204, 0.6)',
			position: common.OverviewRulerLane.Left
		}
	};

	static ADDED_DECORATION_OPTIONS: common.IModelDecorationOptions = {
		linesDecorationsClassName: 'git-dirty-added-diff-glyph',
		isWholeLine: true,
		overviewRuler: {
			color: 'rgba(0, 122, 204, 0.6)',
			darkColor: 'rgba(0, 122, 204, 0.6)',
			position: common.OverviewRulerLane.Left
		}
	};

	static DELETED_DECORATION_OPTIONS: common.IModelDecorationOptions = {
		linesDecorationsClassName: 'git-dirty-deleted-diff-glyph',
		isWholeLine: true,
		overviewRuler: {
			color: 'rgba(0, 122, 204, 0.6)',
			darkColor: 'rgba(0, 122, 204, 0.6)',
			position: common.OverviewRulerLane.Left
		}
	};

	private decorations: string[];
	private diffDelayer: ThrottledDelayer<void>;
	private toDispose: lifecycle.IDisposable[];

	constructor(
		private model: common.IModel,
		private uri: URI,
		@ISCMService private dirtyDiffService: ISCMService,
		@IModelService private modelService: IModelService,
		@IEditorWorkerService private editorWorkerService: IEditorWorkerService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IWorkspaceContextService private contextService: IWorkspaceContextService,
		@ITextModelResolverService private textModelResolverService: ITextModelResolverService
	) {
		this.decorations = [];
		this.diffDelayer = new ThrottledDelayer<void>(200);
		this.toDispose = [];
		this.triggerDiff();
		this.toDispose.push(model.onDidChangeContent(() => this.triggerDiff()));
	}

	@memoize
	private get originalURIPromise(): winjs.TPromise<URI> {
		return this.dirtyDiffService.getBaselineResource(this.uri)
			.then(originalUri => this.textModelResolverService.resolve(originalUri)
				.then(model => {
					const textEditorModel = model.textEditorModel;
					this.toDispose.push(textEditorModel.onDidChangeContent(() => this.triggerDiff()));

					return originalUri;
				}));
	}

	private triggerDiff(): winjs.Promise {
		if (!this.diffDelayer) {
			return winjs.TPromise.as(null);
		}

		return this.diffDelayer.trigger(() => {
			if (!this.model || this.model.isDisposed()) {
				return winjs.TPromise.as<any>([]); // disposed
			}

			return this.originalURIPromise
				.then(uri => this.editorWorkerService.computeDirtyDiff(uri, this.model.uri, true));

		}).then((diff: common.IChange[]) => {
			if (!this.model || this.model.isDisposed()) {
				return; // disposed<commit_msg>ignore diffs for empty original documents<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 { ThrottledDelayer } from 'vs/base/common/async';
import * as lifecycle from 'vs/base/common/lifecycle';
import * as winjs from 'vs/base/common/winjs.base';
import { memoize } from 'vs/base/common/decorators';
import * as ext from 'vs/workbench/common/contributions';
import * as common from 'vs/editor/common/editorCommon';
import * as widget from 'vs/editor/browser/codeEditor';
import { IEventService } from 'vs/platform/event/common/event';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IMessageService } from 'vs/platform/message/common/message';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { ITextModelResolverService } from 'vs/editor/common/services/resolverService';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import URI from 'vs/base/common/uri';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { ISCMService } from 'vs/workbench/services/scm/common/scm';

class DirtyDiffModelDecorator {

	static MODIFIED_DECORATION_OPTIONS: common.IModelDecorationOptions = {
		linesDecorationsClassName: 'git-dirty-modified-diff-glyph',
		isWholeLine: true,
		overviewRuler: {
			color: 'rgba(0, 122, 204, 0.6)',
			darkColor: 'rgba(0, 122, 204, 0.6)',
			position: common.OverviewRulerLane.Left
		}
	};

	static ADDED_DECORATION_OPTIONS: common.IModelDecorationOptions = {
		linesDecorationsClassName: 'git-dirty-added-diff-glyph',
		isWholeLine: true,
		overviewRuler: {
			color: 'rgba(0, 122, 204, 0.6)',
			darkColor: 'rgba(0, 122, 204, 0.6)',
			position: common.OverviewRulerLane.Left
		}
	};

	static DELETED_DECORATION_OPTIONS: common.IModelDecorationOptions = {
		linesDecorationsClassName: 'git-dirty-deleted-diff-glyph',
		isWholeLine: true,
		overviewRuler: {
			color: 'rgba(0, 122, 204, 0.6)',
			darkColor: 'rgba(0, 122, 204, 0.6)',
			position: common.OverviewRulerLane.Left
		}
	};

	private decorations: string[];
	private textEditorModel: common.IModel;
	private diffDelayer: ThrottledDelayer<void>;
	private toDispose: lifecycle.IDisposable[];

	constructor(
		private model: common.IModel,
		private uri: URI,
		@ISCMService private dirtyDiffService: ISCMService,
		@IModelService private modelService: IModelService,
		@IEditorWorkerService private editorWorkerService: IEditorWorkerService,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IWorkspaceContextService private contextService: IWorkspaceContextService,
		@ITextModelResolverService private textModelResolverService: ITextModelResolverService
	) {
		this.decorations = [];
		this.diffDelayer = new ThrottledDelayer<void>(200);
		this.toDispose = [];
		this.triggerDiff();
		this.toDispose.push(model.onDidChangeContent(() => this.triggerDiff()));
	}

	@memoize
	private get originalURIPromise(): winjs.TPromise<URI> {
		return this.dirtyDiffService.getBaselineResource(this.uri)
			.then(originalUri => this.textModelResolverService.resolve(originalUri)
				.then(model => {
					this.textEditorModel = model.textEditorModel;
					this.toDispose.push(this.textEditorModel.onDidChangeContent(() => this.triggerDiff()));

					return originalUri;
				}));
	}

	private triggerDiff(): winjs.Promise {
		if (!this.diffDelayer) {
			return winjs.TPromise.as(null);
		}

		return this.diffDelayer.trigger(() => {
			if (!this.model || this.model.isDisposed()) {
				return winjs.TPromise.as<any>([]); // disposed
			}

			return this.originalURIPromise
				.then(originalURI => this.editorWorkerService.computeDirtyDiff(originalURI, this.model.uri, true));

		}).then((diff: common.IChange[]) => {
			if (!this.model || this.model.isDisposed()) {
				return; // disposed
			}

			if (this.textEditorModel.getValueLength() === 0) {
				diff = [];
{'fraction_non_alphanumeric': 0.1625661071510692, 'fraction_numerical': 0.013221430213842263, 'mean_word_length': 4.039976825028969, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, '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': '2765418', 'n_tokens_mistral': 2928, 'n_tokens_neox': 2624, 'n_words': 522}