"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const path_1 = require("path");
const ts = require("typescript");
const getScriptFileNames_1 = require("../cli/getScriptFileNames");
function createLanguageService(cwd, fileGlobs, compilerOptions, files) {
    const servicesHost = {
        getScriptFileNames: () => getScriptFileNames_1.getScriptFileNames(cwd, fileGlobs),
        getScriptVersion: fileName => {
            const key = path_1.isAbsolute(fileName) ? fileName : path_1.join(cwd, fileName);
            return files[key] && files[key].version.toString();
        },
        getScriptSnapshot: fileName => {
            const pathname = path_1.isAbsolute(fileName) ? fileName : path_1.join(cwd, fileName);
            if (!fs_1.existsSync(pathname)) {
                return undefined;
            }
            return ts.ScriptSnapshot.fromString(fs_1.readFileSync(pathname).toString());
        },
        getCurrentDirectory: () => cwd,
        getCompilationSettings: () => compilerOptions,
        getDefaultLibFileName: options => ts.getDefaultLibFilePath(options),
        fileExists: ts.sys.fileExists,
        readFile: ts.sys.readFile,
        readDirectory: ts.sys.readDirectory,
    };
    return ts.createLanguageService(servicesHost, ts.createDocumentRegistry());
}
exports.createLanguageService = createLanguageService;
//# sourceMappingURL=createLanguageService.js.map