"use strict";
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeLanguageContext = serializeLanguageContext;
exports.serializeFileDiagnostics = serializeFileDiagnostics;
const range_1 = require("../../../../util/vs/editor/common/core/range");
const languageContextService_1 = require("../../../languageServer/common/languageContextService");
function serializeLanguageContext(response) {
    return {
        start: response.start,
        end: response.end,
        items: response.items.map(item => ({
            context: serializeLanguageContextItem(item.context),
            timeStamp: item.timeStamp,
            onTimeout: item.onTimeout,
        }))
    };
}
function serializeLanguageContextItem(context) {
    switch (context.kind) {
        case languageContextService_1.ContextKind.Snippet:
            return serializeSnippetContext(context);
        case languageContextService_1.ContextKind.Trait:
            return serializeTraitContext(context);
        case languageContextService_1.ContextKind.DiagnosticBag:
            return serializeDiagnosticBagContext(context);
    }
}
function serializeSnippetContext(context) {
    return {
        kind: context.kind,
        priority: context.priority,
        uri: context.uri.toString(),
        additionalUris: context.additionalUris?.map(uri => uri.toString()),
        value: context.value
    };
}
function serializeTraitContext(context) {
    return {
        kind: context.kind,
        priority: context.priority,
        name: context.name,
        value: context.value
    };
}
function serializeDiagnosticBagContext(context) {
    const values = context.values.map((diagnostic) => {
        return serializeDiagnostic(diagnostic);
    });
    return {
        kind: context.kind,
        priority: context.priority,
        uri: context.uri.toString(),
        values: values
    };
}
function serializeDiagnostic(diagnostic, resource) {
    const result = {
        severity: diagnostic.severity === 0 ? 'Error' : diagnostic.severity === 1 ? 'Warning' : diagnostic.severity === 2 ? 'Information' : 'Hint',
        message: diagnostic.message,
        source: diagnostic.source || '',
        code: diagnostic.code && !(typeof diagnostic.code === 'number') && !(typeof diagnostic.code === 'string') ? diagnostic.code.value : diagnostic.code,
        range: new range_1.Range(diagnostic.range.start.line + 1, diagnostic.range.start.character + 1, diagnostic.range.end.line + 1, diagnostic.range.end.character + 1).toString(),
    };
    if (resource) {
        result.uri = resource.toString();
    }
    return result;
}
function serializeFileDiagnostics(diagnostics) {
    return diagnostics.flatMap(([resource, diags]) => diags.map(diagnostic => serializeDiagnostic(diagnostic, resource)));
}
//# sourceMappingURL=languageContext.js.map