"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Range = void 0;
const Position_1 = require("./Position");
class Range {
    constructor(start, end) {
        this.start = start;
        this.end = end;
    }
    compare(other) {
        const byStart = this.start.compare(other.start);
        if (byStart !== 0) {
            return byStart;
        }
        return this.end.compare(other.end);
    }
    toLsif() {
        if (this.isSingleLine()) {
            return [this.start.line, this.start.character, this.end.character];
        }
        return [
            this.start.line,
            this.start.character,
            this.end.line,
            this.end.character,
        ];
    }
    static fromLsif(range) {
        const endLine = range.length === 3 ? range[0] : range[2];
        const endCharacter = range.length === 3 ? range[2] : range[3];
        return new Range(new Position_1.Position(range[0], range[1]), new Position_1.Position(endLine, endCharacter));
    }
    static fromNode(node) {
        const sourceFile = node.getSourceFile();
        const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
        const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
        return new Range(new Position_1.Position(start.line, start.character), new Position_1.Position(end.line, end.character));
    }
    isSingleLine() {
        return this.start.line === this.end.line;
    }
}
exports.Range = Range;
