<commit_before>/// <reference path="..\compiler\commandLineParser.ts" />
/// <reference path="..\services\services.ts" />
/// <reference path="utilities.ts" />
/// <reference path="session.ts" />
/// <reference path="scriptVersionCache.ts"/>
/// <reference path="lsHost.ts"/>
/// <reference path="project.ts"/>
/// <reference path="typingsCache.ts"/>

namespace ts.server {
    export const maxProgramSizeForNonTsFiles = 20 * 1024 * 1024;

    export const ContextEvent = "context";
    export const ConfigFileDiagEvent = "configFileDiag";
    export const ProjectLanguageServiceStateEvent = "projectLanguageServiceState";

    export interface ContextEvent {
        eventName: typeof ContextEvent;
        data: { project: Project; fileName: NormalizedPath };
    }

    export interface ConfigFileDiagEvent {
        eventName: typeof ConfigFileDiagEvent;
        data: { triggerFile: string, configFileName: string, diagnostics: Diagnostic[] };
    }

    export interface ProjectLanguageServiceStateEvent {
        eventName: typeof ProjectLanguageServiceStateEvent;
        data: { project: Project, languageServiceEnabled: boolean };
    }

    export type ProjectServiceEvent = ContextEvent | ConfigFileDiagEvent | ProjectLanguageServiceStateEvent;

    export interface ProjectServiceEventHandler {
        (event: ProjectServiceEvent): void;
    }

    export interface SafeList {
        [name: string]: { match: RegExp, exclude?: Array<Array<string | number>>, types?: string[] };
    }

    function prepareConvertersForEnumLikeCompilerOptions(commandLineOptions: CommandLineOption[]): Map<Map<number>> {
        const map: Map<Map<number>> = createMap<Map<number>>();
        for (const option of commandLineOptions) {
            if (typeof option.type === "object") {
                const optionMap = <Map<number>>option.type;
                // verify that map contains only numbers
                optionMap.forEach(value => {
                    Debug.assert(typeof value === "number");
                });
                map.set(option.name, optionMap);
            }
        }
        return map;
    }

    const compilerOptionConverters = prepareConvertersForEnumLikeCompilerOptions(optionDeclarations);
    const indentStyle = createMapFromTemplate({
        "none": IndentStyle.None,
        "block": IndentStyle.Block,
        "smart": IndentStyle.Smart
    });

    const defaultTypeSafeList: SafeList = {
        "jquery": {
            // jquery files can have names like "jquery-1.10.2.min.js" (or "jquery.intellisense.js")
            "match": /jquery(-(\.?\d+)+)?(\.intellisense)?(\.min)?\.js$/gi,
            "types": ["jquery"]
        },
        "WinJS": {
            "match": /^(.*\/winjs)\/base\.js$/gi,        // If the winjs/base.js file is found..
            "exclude": [["^", 1, "/.*"]],                // ..then exclude all files under the winjs folder
            "types": ["winjs"]                           // And fetch the @types package for WinJS
        },
        "Office Nuget": {
            "match": /^(.*\/1\/office)\/excel\.debug\.js$/gi, // Office NuGet package is installed under a "1/office" folder
            "exclude": [["^", 1, "/.*"]],                     // Exclude that whole folder if the file indicated above is found in it
            "types": ["office"]                               // @types package to fetch instead
        }
    };

    export function convertFormatOptions(protocolOptions: protocol.FormatCodeSettings): FormatCodeSettings {
        if (typeof protocolOptions.indentStyle === "string") {
            protocolOptions.indentStyle = indentStyle.get(protocolOptions.indentStyle.toLowerCase());
            Debug.assert(protocolOptions.indentStyle !== undefined);
        }
        return <any>protocolOptions;
    }

    export function convertCompilerOptions(protocolOptions: protocol.ExternalProjectCompilerOptions): CompilerOptions & protocol.CompileOnSaveMixin {
        compilerOptionConverters.forEach((mappedValues, id) => {
            const propertyValue = protocolOptions[id];
            if (typeof propertyValue === "string") {
                protocolOptions[id] = mappedValues.get(propertyValue.toLowerCase());
            }
        });
        return <any>protocolOptions;
    }

    export function tryConvertScriptKindName(scriptKindName: protocol.ScriptKindName | ScriptKind): ScriptKind {
        return typeof scriptKindName === "string"<commit_msg>Add Kendo; fix Office<commit_after>/// <reference path="..\compiler\commandLineParser.ts" />
/// <reference path="..\services\services.ts" />
/// <reference path="utilities.ts" />
/// <reference path="session.ts" />
/// <reference path="scriptVersionCache.ts"/>
/// <reference path="lsHost.ts"/>
/// <reference path="project.ts"/>
/// <reference path="typingsCache.ts"/>

namespace ts.server {
    export const maxProgramSizeForNonTsFiles = 20 * 1024 * 1024;

    export const ContextEvent = "context";
    export const ConfigFileDiagEvent = "configFileDiag";
    export const ProjectLanguageServiceStateEvent = "projectLanguageServiceState";

    export interface ContextEvent {
        eventName: typeof ContextEvent;
        data: { project: Project; fileName: NormalizedPath };
    }

    export interface ConfigFileDiagEvent {
        eventName: typeof ConfigFileDiagEvent;
        data: { triggerFile: string, configFileName: string, diagnostics: Diagnostic[] };
    }

    export interface ProjectLanguageServiceStateEvent {
        eventName: typeof ProjectLanguageServiceStateEvent;
        data: { project: Project, languageServiceEnabled: boolean };
    }

    export type ProjectServiceEvent = ContextEvent | ConfigFileDiagEvent | ProjectLanguageServiceStateEvent;

    export interface ProjectServiceEventHandler {
        (event: ProjectServiceEvent): void;
    }

    export interface SafeList {
        [name: string]: { match: RegExp, exclude?: Array<Array<string | number>>, types?: string[] };
    }

    function prepareConvertersForEnumLikeCompilerOptions(commandLineOptions: CommandLineOption[]): Map<Map<number>> {
        const map: Map<Map<number>> = createMap<Map<number>>();
        for (const option of commandLineOptions) {
            if (typeof option.type === "object") {
                const optionMap = <Map<number>>option.type;
                // verify that map contains only numbers
                optionMap.forEach(value => {
                    Debug.assert(typeof value === "number");
                });
                map.set(option.name, optionMap);
            }
        }
        return map;
    }

    const compilerOptionConverters = prepareConvertersForEnumLikeCompilerOptions(optionDeclarations);
    const indentStyle = createMapFromTemplate({
        "none": IndentStyle.None,
        "block": IndentStyle.Block,
        "smart": IndentStyle.Smart
    });

    const defaultTypeSafeList: SafeList = {
        "jquery": {
            // jquery files can have names like "jquery-1.10.2.min.js" (or "jquery.intellisense.js")
            "match": /jquery(-(\.?\d+)+)?(\.intellisense)?(\.min)?\.js$/gi,
            "types": ["jquery"]
        },
        "WinJS": {
            "match": /^(.*\/winjs)\/base\.js$/gi,        // If the winjs/base.js file is found..
            "exclude": [["^", 1, "/.*"]],                // ..then exclude all files under the winjs folder
            "types": ["winjs"]                           // And fetch the @types package for WinJS
        },
        "Kendo": {
            "match": /^(.*\/kendo\/.+\.js$/gi,
            "exclude": [["^", 1, "/.*"]]
        },
        "Office Loc Files": {
            "match": /^(.*\/office\/1\/\w\w-\w\w\/).+\.js$/gi, // Office NuGet package is installed under a "office/1" folder
            "exclude": [["^", 1, "/.*"]]                     // Exclude that whole folder if the file indicated above is found in it
        },
        "Office Nuget": { // TODO this one
            "match": /^(.*\/1\/office)\/excel\.debug\.js$/gi, // Office NuGet package is installed under a "1/office" folder
            "exclude": [["^", 1, "/.*"]],                     // Exclude that whole folder if the file indicated above is found in it
            "types": ["office"]                               // @types package to fetch instead
        }
    };

    export function convertFormatOptions(protocolOptions: protocol.FormatCodeSettings): FormatCodeSettings {
        if (typeof protocolOptions.indentStyle === "string") {
            protocolOptions.indentStyle = indentStyle.get(protocolOptions.indentStyle.toLowerCase());
            Debug.assert(protocolOptions.indentStyle !== undefined);
        }
        return <any>protocolOptions;
    }

    export function convertCompilerOptions(protocolOptions: protocol.ExternalProjectCompilerOptions): CompilerOptions & protocol.CompileOnSaveMixin {
        compilerOptionConverters.forEach((mappedValues, id) => {
            const propertyValue = protocolOptions[id];
            if (typeof propertyValue === "string") {
                protocolOptions[id] = mappedValues.get(propertyValue.toLowerCase());
            }
        });
        return <any>protocolOptions;
    }

    export function tryConvertScriptKindName(scriptKindName: protocol.ScriptKindName | ScriptKind): ScriptKind {
        return typeof scriptKindName === "string"
{'fraction_non_alphanumeric': 0.1307832033336895, 'fraction_numerical': 0.0042739608932578265, 'mean_word_length': 2.4641006661732052, 'pattern_counts': {'":': 34, '<': 43, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '216151', 'n_tokens_mistral': 2490, 'n_tokens_neox': 2371, 'n_words': 571}