"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toCompletionItem = exports.instanceOfRange = exports.toFoldingRange = exports.toDiagnosticSeverity = exports.rangeDistance = exports.rangeInRange = exports.positionInRange = exports.rangeFromContext = void 0;
const lsp = __importStar(require("vscode-languageserver"));
function rangeFromContext(ctx) {
    const stop = ctx.stop ?? ctx.start;
    return {
        start: {
            line: ctx.start.line - 1,
            character: ctx.start.charPositionInLine
        },
        end: {
            line: stop.line - 1,
            character: stop.charPositionInLine + (stop.stopIndex - stop.startIndex + 1)
        }
    };
}
exports.rangeFromContext = rangeFromContext;
function positionInRange(document, position, range) {
    const currentOffset = document.offsetAt(position);
    const startOffset = document.offsetAt(range.start);
    const endOffset = document.offsetAt(range.end);
    return startOffset <= currentOffset && currentOffset <= endOffset;
}
exports.positionInRange = positionInRange;
function rangeInRange(document, range1, range2) {
    const startOffset1 = document.offsetAt(range1.start);
    const endOffset1 = document.offsetAt(range1.end);
    const startOffset2 = document.offsetAt(range2.start);
    const endOffset2 = document.offsetAt(range2.end);
    return startOffset1 <= startOffset2 && endOffset1 >= endOffset2;
}
exports.rangeInRange = rangeInRange;
function rangeDistance(document, range1, range2) {
    const startOffset1 = document.offsetAt(range1.start);
    const endOffset1 = document.offsetAt(range1.end);
    const startOffset2 = document.offsetAt(range2.start);
    const endOffset2 = document.offsetAt(range2.end);
    return Math.abs(startOffset1 - startOffset2) + Math.abs(endOffset1 - endOffset2);
}
exports.rangeDistance = rangeDistance;
function toDiagnosticSeverity(category) {
    switch (category) {
        case 'error':
            return lsp.DiagnosticSeverity.Error;
        case 'warning':
            return lsp.DiagnosticSeverity.Warning;
        case 'suggestion':
            return lsp.DiagnosticSeverity.Hint;
        default:
            return lsp.DiagnosticSeverity.Error;
    }
}
exports.toDiagnosticSeverity = toDiagnosticSeverity;
function toFoldingRange(range, kind = lsp.FoldingRangeKind.Region) {
    return lsp.FoldingRange.create(range.start.line, range.end.line, range.start.character, range.end.character, kind);
}
exports.toFoldingRange = toFoldingRange;
function instanceOfRange(obj) {
    return 'start' in obj && 'end' in obj;
}
exports.instanceOfRange = instanceOfRange;
function toCompletionItem(type, label, insertText, detail, documentation) {
    switch (type) {
        case 'catalog':
            return {
                kind: lsp.CompletionItemKind.Class,
                label,
                insertText,
                insertTextFormat: lsp.InsertTextFormat.Snippet,
                sortText: `AAA${label}`,
                documentation,
                detail,
                data: 'catalog'
            };
        case 'database':
            return {
                kind: lsp.CompletionItemKind.Enum,
                label,
                insertText,
                insertTextFormat: lsp.InsertTextFormat.Snippet,
                sortText: `BAA${label}`,
                documentation,
                detail,
                data: 'database'
            };
        case 'table':
            return {
                kind: lsp.CompletionItemKind.EnumMember,
                label,
                insertText,
                insertTextFormat: lsp.InsertTextFormat.Snippet,
                sortText: `CBA${label}`,
                documentation,
                detail,
                data: 'table'
            };
        case 'column':
            return {
                kind: lsp.CompletionItemKind.Field,
                label,
                insertText,
                insertTextFormat: lsp.InsertTextFormat.Snippet,
                sortText: `DAA${label}`,
                documentation,
                detail,
                data: 'column'
            };
        case 'view':
            return {
                kind: lsp.CompletionItemKind.EnumMember,
                label,
                insertText,
                insertTextFormat: lsp.InsertTextFormat.Snippet,
                sortText: `CAA${label}`,
                documentation,
                detail,
                data: 'view'
            };
        case 'function':
            return {
                kind: lsp.CompletionItemKind.Property,
                label,
                insertText: `\`${insertText}\``,
                insertTextFormat: lsp.InsertTextFormat.Snippet,
                sortText: `EAA${label}`,
                documentation,
                detail,
                data: 'function'
            };
        case 'built-in':
            return {
                kind: lsp.CompletionItemKind.Function,
                label,
                insertText,
                insertTextFormat: lsp.InsertTextFormat.Snippet,
                sortText: `FAA${label}`,
                documentation,
                detail,
                data: 'function'
            };
    }
}
exports.toCompletionItem = toCompletionItem;
//# sourceMappingURL=protocol-translation.js.map