<commit_before>/*
 * Copyright 2013 Palantir Technologies, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

///<reference path='../typescript/src/compiler/io.ts'/>
///<reference path='../typescript/src/services/languageService.ts'/>

module Bridge {

    export class ScriptSnapshot implements TypeScript.IScriptSnapshot {

        private version: number;
        private open: boolean;
        private content: string;
        private changes: TypeScript.TextChangeRange[];
        private lineStartPositions: number[];
        private maxChanges = 100;

        constructor(private file: string) {
            this.version = 0;
            this.open = true;
            this.updateContent(readFileContents(file));
        }

        public updateContent(content: string, resetChanges: boolean = true): void {
            if (resetChanges) {
                this.changes = [];
            }
            this.content = content;
            this.lineStartPositions = TypeScript.TextUtilities.parseLineStarts(TypeScript.SimpleText.fromString(this.content));
            this.version++;
        }

        public updateFile(file: string): void {
            var content = readFileContents(file);

            this.updateContent(content);
        }

        public getVersion(): number {
            return this.version;
        }

        public isOpen(): boolean {
            return this.open;
        }

        public setOpen(): void {
            this.open = true;
        }

        public setClosed(): void {
            this.open = false;
        }

        public addEdit(offset: number, length: number, replacementText: string): void {
            if (this.changes.length >= this.maxChanges) {
                this.changes = [];
            }
            var beforeEdit = this.content.substring(0, offset);
            var afterEdit = this.content.substring(offset + length, this.content.length);
            var newContent = beforeEdit + replacementText + afterEdit;
            var textChangeRange = new TypeScript.TextChangeRange(TypeScript.TextSpan.fromBounds(offset, offset + length), replacementText.length);
            this.changes.push(textChangeRange);
            this.updateContent(newContent, false);
        }

        public getText(start: number, end: number): string {
            return this.content.substring(start, end);
        }

        public getLength(): number {<commit_msg>Make maxChanges static and rename it to indicate that its constant<commit_after>/*
 * Copyright 2013 Palantir Technologies, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

///<reference path='../typescript/src/compiler/io.ts'/>
///<reference path='../typescript/src/services/languageService.ts'/>

module Bridge {

    export class ScriptSnapshot implements TypeScript.IScriptSnapshot {

        private static MAX_CHANGES = 100;

        private version: number;
        private open: boolean;
        private content: string;
        private changes: TypeScript.TextChangeRange[];
        private lineStartPositions: number[];

        constructor(private file: string) {
            this.version = 0;
            this.open = true;
            this.updateContent(readFileContents(file));
        }

        public updateContent(content: string, resetChanges: boolean = true): void {
            if (resetChanges) {
                this.changes = [];
            }
            this.content = content;
            this.lineStartPositions = TypeScript.TextUtilities.parseLineStarts(TypeScript.SimpleText.fromString(this.content));
            this.version++;
        }

        public updateFile(file: string): void {
            var content = readFileContents(file);

            this.updateContent(content);
        }

        public getVersion(): number {
            return this.version;
        }

        public isOpen(): boolean {
            return this.open;
        }

        public setOpen(): void {
            this.open = true;
        }

        public setClosed(): void {
            this.open = false;
        }

        public addEdit(offset: number, length: number, replacementText: string): void {
            if (this.changes.length >= ScriptSnapshot.MAX_CHANGES) {
                this.changes = [];
            }
            var beforeEdit = this.content.substring(0, offset);
            var afterEdit = this.content.substring(offset + length, this.content.length);
            var newContent = beforeEdit + replacementText + afterEdit;
            var textChangeRange = new TypeScript.TextChangeRange(TypeScript.TextSpan.fromBounds(offset, offset + length), replacementText.length);
            this.changes.push(textChangeRange);
            this.updateContent(newContent, false);
        }

        public getText(start: number, end: number): string {
            return this.content.substring(start, end);
        }

        public getLength(): number {
{'fraction_non_alphanumeric': 0.09515775265733085, 'fraction_numerical': 0.00438670490973511, 'mean_word_length': 2.298831385642738, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5733682', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1431, 'n_words': 435}