var g = Object.defineProperty;
var f = (t, e) => g(t, "name", { value: e, configurable: !0 });
import { completionStatus as h } from "../../../../../@codemirror_autocomplete@6.18.6/node_modules/@codemirror/autocomplete/dist/index.js";
import { ChangeSet as C, Transaction as S } from "../../../../../@codemirror_state@6.5.2/node_modules/@codemirror/state/dist/index.js";
import { getCodeiumCompletions as T, completionsToChangeSpec as x } from "./codeium.js";
import { addSuggestions as y } from "./effects.js";
import { copilotIgnore as D, copilotEvent as I } from "./annotations.js";
import { codeiumConfig as O, codeiumOtherDocumentsConfig as q } from "./config.js";
async function v(t, e) {
  const m = t.state.facet(O), { override: p } = t.state.facet(q), l = await p(), n = t.state, s = n.selection.main.head, u = n.doc.toString();
  try {
    const o = await T({
      text: u,
      cursorOffset: s,
      config: m,
      otherDocuments: l
    });
    if (!o || o.completionItems.length === 0 || !((e === void 0 || s === e) && h(t.state) !== "active" && t.hasFocus))
      return;
    const c = x(o), i = 0, r = c.at(i);
    if (!r)
      return;
    const a = C.of(r, n.doc.length), d = a.invert(n.doc);
    t.dispatch({
      changes: a,
      effects: y.of({
        index: i,
        reverseChangeSet: d,
        changeSpecs: c
      }),
      annotations: [
        D.of(null),
        I.of(null),
        S.addToHistory.of(!1)
      ]
    });
  } catch (o) {
    console.warn("copilot completion failed", o), await new Promise((c) => setTimeout(c, 300));
  }
}
f(v, "requestCompletion");
export {
  v as requestCompletion
};
