<commit_before>'use strict';

import * as fs from 'fs';
import * as path from 'path';
import * as cp from 'child_process';
import * as vsc from 'vscode';

export default class Server extends vsc.Disposable {
    public static path: string;

    public constructor(paths?: string[]) {
        super(null);
        this.start(paths);
    }

    public dispose() {
        this.stop();
    }

    public start(paths?: string[]) {
        let additions = new Set<string>();
        let additionsArray: string[] = [];

        if (paths) {
            for (let i = 0; i < paths.length; i++) {
                let dirs = this.importDirs(paths[i]);

                dirs.forEach((dir) => {
                    additions.add('-I' + dir);
                });
            }
        }

        if (vsc.workspace.rootPath) {
            this.importDirs(vsc.workspace.rootPath + path.sep).forEach((dir) => {
                additions.add('-I' + dir);
            });
        }

        additions.forEach((item) => {
            additionsArray.push(item);
        })

        cp.spawn(Server.path + 'dcd-server', additionsArray, { stdio: 'ignore' });
    }

    public stop() {
        cp.spawn('dcd-client', ['--shutdown']);
    }

    private importDirs(path: string) {
        let imp = new Set<string>();

        ['json', 'sdl'].forEach((dubExt) => {
            let dubFile = path + 'dub.' + dubExt;

            try {
                fs.accessSync(dubFile, fs.R_OK);
                let dub: any;
                let sourcePaths: string[] = [];

                if (dubExt === 'json') {
                    dub = require(dubFile);<commit_msg>Make the server aware of the current directory<commit_after>'use strict';

import * as fs from 'fs';
import * as path from 'path';
import * as cp from 'child_process';
import * as vsc from 'vscode';

export default class Server extends vsc.Disposable {
    public static path: string;

    public constructor(paths?: string[]) {
        super(null);
        this.start(paths);
    }

    public dispose() {
        this.stop();
    }

    public start(paths?: string[]) {
        let additions = new Set<string>();
        let additionsImports: string[] = [];

        if (paths) {
            for (let i = 0; i < paths.length; i++) {
                let dirs = this.importDirs(paths[i]);

                dirs.forEach((dir) => {
                    additions.add(dir);
                });
            }
        }

        if (vsc.workspace.rootPath) {
            this.importDirs(vsc.workspace.rootPath + path.sep).forEach((dir) => {
                additions.add(dir);
            });

            additions.add(vsc.workspace.rootPath);
        }

        additions.forEach((item) => {
            additionsImports.push('-I' + item);
        })

        cp.spawn(Server.path + 'dcd-server', additionsImports, { stdio: 'ignore' });
    }

    public stop() {
        cp.spawn('dcd-client', ['--shutdown']);
    }

    private importDirs(path: string) {
        let imp = new Set<string>();

        ['json', 'sdl'].forEach((dubExt) => {
            let dubFile = path + 'dub.' + dubExt;

            try {
                fs.accessSync(dubFile, fs.R_OK);
                let dub: any;
                let sourcePaths: string[] = [];

                if (dubExt === 'json') {
                    dub = require(dubFile);
{'fraction_non_alphanumeric': 0.14788312462731068, 'fraction_numerical': 0.0005963029218843172, 'mean_word_length': 1.6626984126984128, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '7613936', 'n_tokens_mistral': 1034, 'n_tokens_neox': 974, 'n_words': 226}