import { sanitizeRanges } from "./syntaxRangeProvider.mjs";
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(sanitizeRanges(foldingRangeData, Number.MAX_VALUE));
  }
}
export {
  ID_INIT_PROVIDER,
  InitializingRangeProvider
};
