@gdquest/gd-exercise
Version:
Core package that handles logic for the GDExercise project.
5 lines (4 loc) • 6.48 kB
JavaScript
import{linter as q,setDiagnostics as I}from"@codemirror/lint";import{ViewPlugin as J}from"@codemirror/view";var L=Object.create,O=Object.defineProperty,S=Object.getOwnPropertyDescriptor,P=Object.getOwnPropertyNames,j=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty,D=(n,t)=>function(){return t||(0,n[P(n)[0]])((t={exports:{}}).exports,t),t.exports},N=(n,t,s,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of P(t))!A.call(n,u)&&u!==s&&O(n,u,{get:()=>t[u],enumerable:!(r=S(t,u))||r.enumerable});return n},k=(n,t,s)=>(s=n!=null?L(j(n)):{},N(t||!n||!n.__esModule?O(s,"default",{value:n,enumerable:!0}):s,n)),R=D({"../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js"(n,t){"use strict";var s=Object.prototype.hasOwnProperty,r="~";function u(){}Object.create&&(u.prototype=Object.create(null),new u().__proto__||(r=!1));function d(h,o,i){this.fn=h,this.context=o,this.once=i||!1}function g(h,o,i,a,l){if(typeof i!="function")throw new TypeError("The listener must be a function");var c=new d(i,a||h,l),f=r?r+o:o;return h._events[f]?h._events[f].fn?h._events[f]=[h._events[f],c]:h._events[f].push(c):(h._events[f]=c,h._eventsCount++),h}function _(h,o){--h._eventsCount===0?h._events=new u:delete h._events[o]}function p(){this._events=new u,this._eventsCount=0}p.prototype.eventNames=function(){var o=[],i,a;if(this._eventsCount===0)return o;for(a in i=this._events)s.call(i,a)&&o.push(r?a.slice(1):a);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(i)):o},p.prototype.listeners=function(o){var i=r?r+o:o,a=this._events[i];if(!a)return[];if(a.fn)return[a.fn];for(var l=0,c=a.length,f=new Array(c);l<c;l++)f[l]=a[l].fn;return f},p.prototype.listenerCount=function(o){var i=r?r+o:o,a=this._events[i];return a?a.fn?1:a.length:0},p.prototype.emit=function(o,i,a,l,c,f){var m=r?r+o:o;if(!this._events[m])return!1;var e=this._events[m],y=arguments.length,w,v;if(e.fn){switch(e.once&&this.removeListener(o,e.fn,void 0,!0),y){case 1:return e.fn.call(e.context),!0;case 2:return e.fn.call(e.context,i),!0;case 3:return e.fn.call(e.context,i,a),!0;case 4:return e.fn.call(e.context,i,a,l),!0;case 5:return e.fn.call(e.context,i,a,l,c),!0;case 6:return e.fn.call(e.context,i,a,l,c,f),!0}for(v=1,w=new Array(y-1);v<y;v++)w[v-1]=arguments[v];e.fn.apply(e.context,w)}else{var E=e.length,b;for(v=0;v<E;v++)switch(e[v].once&&this.removeListener(o,e[v].fn,void 0,!0),y){case 1:e[v].fn.call(e[v].context);break;case 2:e[v].fn.call(e[v].context,i);break;case 3:e[v].fn.call(e[v].context,i,a);break;case 4:e[v].fn.call(e[v].context,i,a,l);break;default:if(!w)for(b=1,w=new Array(y-1);b<y;b++)w[b-1]=arguments[b];e[v].fn.apply(e[v].context,w)}}return!0},p.prototype.on=function(o,i,a){return g(this,o,i,a,!1)},p.prototype.once=function(o,i,a){return g(this,o,i,a,!0)},p.prototype.removeListener=function(o,i,a,l){var c=r?r+o:o;if(!this._events[c])return this;if(!i)return _(this,c),this;var f=this._events[c];if(f.fn)f.fn===i&&(!l||f.once)&&(!a||f.context===a)&&_(this,c);else{for(var m=0,e=[],y=f.length;m<y;m++)(f[m].fn!==i||l&&!f[m].once||a&&f[m].context!==a)&&e.push(f[m]);e.length?this._events[c]=e.length===1?e[0]:e:_(this,c)}return this},p.prototype.removeAllListeners=function(o){var i;return o?(i=r?r+o:o,this._events[i]&&_(this,i)):(this._events=new u,this._eventsCount=0),this},p.prototype.off=p.prototype.removeListener,p.prototype.addListener=p.prototype.on,p.prefixed=r,p.EventEmitter=p,typeof t<"u"&&(t.exports=p)}}),C=k(R(),1),B=C.default,V=class extends Error{constructor(n,t){let{cause:s,code:r,response:u}=t??{};super(n,{cause:s}),this.code=0,this.response=null,r!=null&&(this.code=r),u!=null&&(this.response=u)}},M=class extends B{constructor(){super(...arguments),this._requests=new Map,this._lastId=0}async send(n){return await new Promise((t,s)=>{Array.isArray(n)?this._processBatch(n,t):this._process(n,t,s)})}notify(n){if(Array.isArray(n)){new Promise(t=>{this._processBatch(n,t)}).catch(t=>{console.error("Error while processing batch:",t)});return}new Promise((t,s)=>{this._process(n,t,s)}).catch(t=>{console.error("Error while running process:",t)})}_process(n,t,s){let r=this._lastId;this._lastId+=1;let u={jsonrpc:"2.0",id:r,...n},d=()=>{this.off("response",g),this.off("error",_)},g=p=>{p.id===r&&(t(p),d())},_=p=>{if(p.id===r){let h=new V(p.error.message,{code:p.error.code,response:p});s(h),d()}};this.on("response",g),this.on("error",_),this.emit("request",JSON.stringify(u))}_processBatch(n,t){let s=n.map(u=>{let d={jsonrpc:"2.0",id:this._lastId,...u};return this._lastId+=1,d}),r=u=>{let d=[];for(let g of u)for(let _ of s)_.id===g.id&&d.push(g);d.length>0&&(t(d),this.off("batch",r))};this.on("batch",r),this.emit("request",s)}};function x(n,t){let s=0,r=0;for(let u=0;u<n.length;u++){if(n[u]===`
`?(s+=1,r=0):r+=1,t.line<s)return 0;if(s===t.line&&r===t.character)return u+1}return n.length}function G(n,t){let s=0,r=0;for(let u=1;u<n.length;u++)if(n[u-1]===`
`?(s+=1,r=0):r+=1,u===t)return{line:s,character:r};return{line:s,character:r}}function F(n){switch(n){case 1:return"error";case 2:return"warning";case 3:case 4:default:return"info"}}function H(n){let t=new C.default,s=null,r=0,{autocompletion:u=!0,onClientCommand:d,getData:g}=n,_=new M;class p{constructor(c){this.view=c}update(c){}}J.fromClass(p);let h=q(async l=>{s=l,t.emit("view",l);let c=[],f=r;return r+=1,_.notify({method:"textDocument/didChange",params:{textDocument:{uri:"file:///whatever",version:f},contentChanges:[{text:l.state.doc.toString()}]}}),c},{});_.on("request",l=>{d(l)});let o=l=>{switch(l.method){case"textDocument/publishDiagnostics":i(l);break}};_.on("notification",o);let i=l=>{if(console.log("onPublishDiagnostics",l,s),s==null)return;let c=l.params.diagnostics.map(e=>({from:x(s?.state.doc.toString()??"",e.range.start),to:x(s?.state.doc.toString()??"",e.range.end),severity:F(e.severity),source:e.source,message:e.message}));console.log("diagnostics",c);let f=I(s.state,c),m=s.state.update(f);s.dispatch(m)};return g({emitServerCommand:l=>{let c=JSON.parse(l);if(typeof c=="string")throw new Error("JSON is string");if(Array.isArray(c)){let f=[];for(let m of c)"method"in m?_.emit("notification",m):f.push(m);_.emit("batch",f);return}if("error"in c){_.emit("error",c);return}if("result"in c){_.emit("response",c);return}if("method"in c){_.emit("notification",c);return}throw new Error("unknown error")}}),[h,...u?[]:[]]}export{x as a,G as b,F as c,H as d};
//# sourceMappingURL=chunk-XAPRL75U.min.mjs.map