var TypeScript = require("../typescript/tss");

var lsh = require("./languageServiceHost");

function createDefaultFormatCodeOptions() {
    return new TypeScript.Services.FormatCodeOptions();
}
exports.createDefaultFormatCodeOptions = createDefaultFormatCodeOptions;

function getSyntaxTreeByContent(content, compilationSettings) {
    var languageServiceHost = new lsh.LanguageServiceHostImpl();
    var filePath = "tmp.ts";

    languageServiceHost.addFile({
        fileName: filePath,
        version: 0,
        open: false,
        byteOrderMark: 0 /* None */,
        snapshot: TypeScript.ScriptSnapshot.fromString(content)
    });
    if (compilationSettings) {
        languageServiceHost.setCompilationSettings(compilationSettings);
    }
    var languageService = new TypeScript.Services.LanguageService(languageServiceHost);
    return languageService.getSyntaxTree(filePath);
}
exports.getSyntaxTreeByContent = getSyntaxTreeByContent;

function getAstByContent(content, compilationSettings) {
    var syntaxTree = exports.getSyntaxTreeByContent(content, compilationSettings);
    var immutableSettings = TypeScript.ImmutableCompilationSettings.fromCompilationSettings(compilationSettings);

    return TypeScript.SyntaxTreeToAstVisitor.visit(syntaxTree, "tmp.ts", immutableSettings, false);
}
exports.getAstByContent = getAstByContent;
