import{a as e}from"./chunk-D9Tnb9aB.js";import{t}from"./codemirror-DtW92bSi.js";import{g as n,h as r,i,n as a,t as o}from"./definition-C7QrKMH2.js";import{t as s}from"./scalars-DI3Jri1T.js";import{t as c}from"./forEachState-CVF2k4ot.js";var l=e(t());function u(e,t,n){let r=d(n,p(t.string));if(!r)return;let i=t.type!==null&&/"|\w/.test(t.string[0])?t.start:t.end;return{list:r,from:{line:e.line,ch:i},to:{line:e.line,ch:t.end}}}function d(e,t){return t?f(f(e.map(e=>({proximity:m(p(e.text),t),entry:e})),e=>e.proximity<=2),e=>!e.entry.isDeprecated).sort((e,t)=>(e.entry.isDeprecated?1:0)-(t.entry.isDeprecated?1:0)||e.proximity-t.proximity||e.entry.text.length-t.entry.text.length).map(e=>e.entry):f(e,e=>!e.isDeprecated)}function f(e,t){let n=e.filter(t);return n.length===0?e:n}function p(e){return e.toLowerCase().replaceAll(/\W/g,``)}function m(e,t){let n=h(t,e);return e.length>t.length&&(n-=e.length-t.length-1,n+=e.indexOf(t)===0?0:.5),n}function h(e,t){let n,r,i=[],a=e.length,o=t.length;for(n=0;n<=a;n++)i[n]=[n];for(r=1;r<=o;r++)i[0][r]=r;for(n=1;n<=a;n++)for(r=1;r<=o;r++){let a=e[n-1]===t[r-1]?0:1;i[n][r]=Math.min(i[n-1][r]+1,i[n][r-1]+1,i[n-1][r-1]+a),n>1&&r>1&&e[n-1]===t[r-2]&&e[n-2]===t[r-1]&&(i[n][r]=Math.min(i[n][r],i[n-2][r-2]+a))}return i[a][o]}l.default.registerHelper(`hint`,`graphql-variables`,(e,t)=>{let n=e.getCursor(),r=e.getTokenAt(n),i=g(n,r,t);return i?.list&&i.list.length>0&&(i.from=l.default.Pos(i.from.line,i.from.ch),i.to=l.default.Pos(i.to.line,i.to.ch),l.default.signal(e,`hasCompletion`,e,i,r)),i});function g(e,t,n){let{kind:i,step:c}=t.state.kind===`Invalid`?t.state.prevState:t.state;if(i===`Document`&&c===0)return u(e,t,[{text:`{`}]);let{variableToType:l}=n;if(!l)return;let d=_(l,t.state);if(i===`Document`||i===`Variable`&&c===0)return u(e,t,Object.keys(l).map(e=>({text:`"${e}": `,type:l[e]})));if((i===`ObjectValue`||i===`ObjectField`&&c===0)&&d.fields)return u(e,t,Object.keys(d.fields).map(e=>d.fields[e]).map(e=>({text:`"${e.name}": `,type:e.type,description:e.description})));if(i===`StringValue`||i===`NumberValue`||i===`BooleanValue`||i===`NullValue`||i===`ListValue`&&c===1||i===`ObjectField`&&c===2||i===`Variable`&&c===2){let n=d.type?r(d.type):void 0;if(n instanceof a)return u(e,t,[{text:`{`}]);if(n instanceof o)return u(e,t,n.getValues().map(e=>({text:`"${e.name}"`,type:n,description:e.description})));if(n===s)return u(e,t,[{text:`true`,type:s,description:`Not false.`},{text:`false`,type:s,description:`Not true.`}])}}function _(e,t){let o={type:null,fields:null};return c(t,t=>{switch(t.kind){case`Variable`:o.type=e[t.name];break;case`ListValue`:{let e=o.type?n(o.type):void 0;o.type=e instanceof i?e.ofType:null;break}case`ObjectValue`:{let e=o.type?r(o.type):void 0;o.fields=e instanceof a?e.getFields():null;break}case`ObjectField`:o.type=(t.name&&o.fields?o.fields[t.name]:null)?.type;break}}),o}
//# sourceMappingURL=hint-B6AAvP9T.js.map