<commit_before>/*
 * Copyright (C) 2017 TypeFox and others.
 *
 * 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
 */

import { injectable, inject, decorate } from "inversify";
import {
    MonacoWorkspace as BaseMonacoWorkspace, ProtocolToMonacoConverter, MonacoToProtocolConverter, testGlob
} from "monaco-languageclient";
import { DisposableCollection } from "../../application/common";
import { FileChangeType, FileSystem, FileSystemWatcher } from '../../filesystem/common';
import * as lang from "../../languages/common";
import { Emitter, Event, TextDocument, TextDocumentWillSaveEvent, TextEdit } from "../../languages/common";
import { MonacoModelResolver } from "./monaco-model-resolver";
import { WillSaveModelEvent } from "./monaco-editor-model";

decorate(injectable(), BaseMonacoWorkspace);
decorate(inject(MonacoToProtocolConverter), BaseMonacoWorkspace, 0);

@injectable()
export class MonacoWorkspace extends BaseMonacoWorkspace implements lang.Workspace {
    readonly capabilities = {
        applyEdit: true,
        workspaceEdit: {
            documentChanges: true
        }
    };

    readonly synchronization = {
        didSave: true,
        willSave: true,
        willSaveWaitUntil: true
    };

    protected resolveReady: () => void;
    readonly ready = new Promise<void>(resolve => {
        this.resolveReady = resolve;
    });
    protected readonly onWillSaveTextDocumentEmitter = new Emitter<TextDocumentWillSaveEvent>();
    protected readonly onDidSaveTextDocumentEmitter = new Emitter<TextDocument>();

    constructor(
        @inject(FileSystem) protected readonly fileSystem: FileSystem,
        @inject(FileSystemWatcher) protected readonly fileSystemWatcher: FileSystemWatcher,
        @inject(MonacoModelResolver) protected readonly monacoModelResolver: MonacoModelResolver,
        @inject(MonacoToProtocolConverter) protected readonly m2p: MonacoToProtocolConverter,
        @inject(ProtocolToMonacoConverter) protected readonly p2m: ProtocolToMonacoConverter
    ) {
        super(m2p);
        fileSystem.getWorkspaceRoot().then(rootStat => {
            this._rootUri = rootStat.uri;
            this.resolveReady();
        });
        monaco.editor.onDidCreateModel(model => {
            this.monacoModelResolver.createModelReference(model.uri).then(reference => {
                reference.object.onDidSaveModel(model =>
                    this.onDidSaveModel(model)
                );
                reference.object.onWillSaveModel(event =>
                    this.onWillSaveModel(event)
                );
                reference.dispose();
            });
        });
    }
<commit_msg>[LS] Support `rootPath` property<commit_after>/*
 * Copyright (C) 2017 TypeFox and others.
 *
 * 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
 */

import { injectable, inject, decorate } from "inversify";
import {
    MonacoWorkspace as BaseMonacoWorkspace, ProtocolToMonacoConverter, MonacoToProtocolConverter, testGlob
} from "monaco-languageclient";
import { DisposableCollection } from "../../application/common";
import { FileChangeType, FileSystem, FileSystemWatcher } from '../../filesystem/common';
import * as lang from "../../languages/common";
import { Emitter, Event, TextDocument, TextDocumentWillSaveEvent, TextEdit } from "../../languages/common";
import { MonacoModelResolver } from "./monaco-model-resolver";
import { WillSaveModelEvent } from "./monaco-editor-model";
import URI from "../../application/common/uri";

decorate(injectable(), BaseMonacoWorkspace);
decorate(inject(MonacoToProtocolConverter), BaseMonacoWorkspace, 0);

@injectable()
export class MonacoWorkspace extends BaseMonacoWorkspace implements lang.Workspace {
    readonly capabilities = {
        applyEdit: true,
        workspaceEdit: {
            documentChanges: true
        }
    };

    readonly synchronization = {
        didSave: true,
        willSave: true,
        willSaveWaitUntil: true
    };

    protected resolveReady: () => void;
    readonly ready = new Promise<void>(resolve => {
        this.resolveReady = resolve;
    });
    protected readonly onWillSaveTextDocumentEmitter = new Emitter<TextDocumentWillSaveEvent>();
    protected readonly onDidSaveTextDocumentEmitter = new Emitter<TextDocument>();

    constructor(
        @inject(FileSystem) protected readonly fileSystem: FileSystem,
        @inject(FileSystemWatcher) protected readonly fileSystemWatcher: FileSystemWatcher,
        @inject(MonacoModelResolver) protected readonly monacoModelResolver: MonacoModelResolver,
        @inject(MonacoToProtocolConverter) protected readonly m2p: MonacoToProtocolConverter,
        @inject(ProtocolToMonacoConverter) protected readonly p2m: ProtocolToMonacoConverter
    ) {
        super(m2p);
        fileSystem.getWorkspaceRoot().then(rootStat => {
            this._rootUri = rootStat.uri;
            this.resolveReady();
        });
        monaco.editor.onDidCreateModel(model => {
            this.monacoModelResolver.createModelReference(model.uri).then(reference => {
                reference.object.onDidSaveModel(model =>
                    this.onDidSaveModel(model)
                );
                reference.object.onWillSaveModel(event =>
                    this.onWillSaveModel(event)
                );
                reference.dispose();
            });
        });
    }

    get rootPath(): string | null {
        return this._rootUri && new URI(this._rootUri).path()
    }

{'fraction_non_alphanumeric': 0.10230795728556666, 'fraction_numerical': 0.004133654839820875, 'mean_word_length': 3.1657101865136297, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, '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': '3854740', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1486, 'n_words': 353}