"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const syntaxRangeProvider = require("./syntaxRangeProvider.js");
const ID_INIT_PROVIDER = "init";
class InitializingRangeProvider {
  constructor(editorModel, initialRanges, onTimeout, timeoutTime) {
    this.editorModel = editorModel;
    this.id = ID_INIT_PROVIDER;
    if (initialRanges.length) {
      let toDecorationRange = (range) => {
        return {
          range: {
            startLineNumber: range.startLineNumber,
            startColumn: 0,
            endLineNumber: range.endLineNumber,
            endColumn: editorModel.getLineLength(range.endLineNumber)
          },
          options: {
            description: "folding-initializing-range-provider",
            stickiness: 1
            /* NeverGrowsWhenTypingAtEdges */
          }
        };
      };
      this.decorationIds = editorModel.deltaDecorations([], initialRanges.map(toDecorationRange));
      this.timeout = setTimeout(onTimeout, timeoutTime);
    }
  }
  dispose() {
    if (this.decorationIds) {
      this.editorModel.deltaDecorations(this.decorationIds, []);
      this.decorationIds = void 0;
    }
    if (typeof this.timeout === "number") {
      clearTimeout(this.timeout);
      this.timeout = void 0;
    }
  }
  compute(cancelationToken) {
    let foldingRangeData = [];
    if (this.decorationIds) {
      for (let id of this.decorationIds) {
        let range = this.editorModel.getDecorationRange(id);
        if (range) {
          foldingRangeData.push({ start: range.startLineNumber, end: range.endLineNumber, rank: 1 });
        }
      }
    }
    return Promise.resolve(syntaxRangeProvider.sanitizeRanges(foldingRangeData, Number.MAX_VALUE));
  }
}
exports.ID_INIT_PROVIDER = ID_INIT_PROVIDER;
exports.InitializingRangeProvider = InitializingRangeProvider;
