var h=Object.create;var f=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var u=(e,t)=>f(e,"name",{value:t,configurable:!0});var U=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var A=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of w(t))!R.call(e,r)&&r!==o&&f(e,r,{get:()=>t[r],enumerable:!(s=y(t,r))||s.enumerable});return e};var K=(e,t,o)=>(o=e!=null?h(E(e)):{},A(t||!e||!e.__esModule?f(o,"default",{value:e,enumerable:!0}):o,e));import*as k from"antlr4-c3";import{CharStream as S,CommonTokenStream as z}from"antlr4ng";var v=/[\w]$/,g=/\r\n|\n|\r/g;function P(e,t){let o=e.column,s=e.column+(e.text?.length||0),r=e.line,n=e.type!==t||!e.text?r:r+(e.text.match(g)?.length||0);return{startColumn:o,startLine:r,endColumn:s,endLine:n}}u(P,"getTokenPosition");function Q(e,t,o,s){let r=t.column-1;for(let n=0;n<e.size;n++){let a=e.get(n),{startColumn:m,startLine:i,endColumn:c,endLine:x}=P(a,o);if(x>t.line||i===t.line&&c>r)return s?n:n>0&&i===t.line&&m===r&&v.test(e.get(n-1).text||"")?n-1:e.get(n).type===o?n+1:n}}u(Q,"findCursorTokenIndex");function C(e,t){let o=e.split(g),s=e.match(g),r="";s&&(r=s[0]);let n=0;return o.reduce((a,m,i)=>(t.line-1===i&&(a.length?n=a.length+t.column:n=t.column-1),i===0?m:a+r+m),""),n}u(C,"getCursorIndex");function W(e,t){return e===t.startTokenIndex}u(W,"isStartingToWriteRule");function $(e,t){let o=e.slice(0,t-1),s=e.slice(t-1),r=o.lastIndexOf(";"),n=s.indexOf(";"),a=r>-1?r+1:0,m=n>-1?n+o.length:e.length,i=e.slice(a,m),c=t-a;return{statement:i,cursorIndex:c}}u($,"getCurrentStatement");var l=`(\\s|\r
|
|\r)+`,N=new RegExp(`^(${l})?explain${l}$`),B=new RegExp(`^(${l})?\\S+${l}`);function X(e,t){let o=C(e,t),s=$(e,o),r=s.statement.slice(0,s.cursorIndex).toLowerCase();return!!(o===0||!r.match(B)||r.match(N))}u(X,"shouldSuggestTemplates");function L(e,t,o){let s=S.fromString(o),r=new e(s),n=new z(r),a=new t(n);return a.removeErrorListeners(),a}u(L,"createParser");function Y(e,t){let o=S.fromString(t);return new e(o)}u(Y,"createLexer");var d=class{static{u(this,"SqlErrorListener")}constructor(t){this.errors=[],this.whitespaceToken=t}syntaxError(t,o,s,r,n){if(o){let a=P(o,this.whitespaceToken);this.errors.push({message:n,...a})}else this.errors.push({message:n,startLine:s,startColumn:r,endLine:s,endColumn:r})}reportAmbiguity(){}reportAttemptingFullContext(){}reportContextSensitivity(){}};var F=(o=>(o.Autocomplete="autocomplete",o.Tokens="tokens",o))(F||{});function ie(e,t,o,s,r,n,a,m){let i=L(t,o,e),{tokenStream:c}=i,x=new d(s);i.removeErrorListeners(),i.addErrorListener(x),m(i);let p=O(i,c,a,n);return p.length?{statementPositions:p,strategy:"autocomplete"}:{statementPositions:G(c,r,n),strategy:"tokens"}}u(ie,"extractStatementPositionsFromQuery");function G(e,t,o){let s=0,r=!1,n=e.size-2,a=[];for(let m=0;m<=n;m++){let i=e.get(m),c=i.type===o,x=t.includes(i.type);if(!r&&x)continue;if(r||(r=!0,s=i.start),c&&s===i.start){r=!1;continue}if(c||m===n){let T=i.text?.length||0,b=i.start+T,I={startIndex:s,endIndex:b};a.push(I)}c&&(r=!1)}return a}u(G,"extractStatementsUsingTokens");function O(e,t,o,s){let r=new k.CodeCompletionCore(e);r.preferredRules=new Set([o]);let n=t.get(t.size-2),a=[];for(;n?.tokenIndex>0;){let m=r.collectCandidates(n.tokenIndex).rules;!m.size&&n.type===s&&(m=r.collectCandidates(n.tokenIndex-1).rules);let i;for(let[c,{startTokenIndex:x}]of m)if(c===o){i=t.get(x);break}if(!i)break;if(i.tokenIndex>n.tokenIndex){n=t.get(n.tokenIndex-1);continue}a.push({startIndex:i.start,endIndex:n.start+(n.text?.length||0)}),n=t.get(i.tokenIndex-1)}return a.reverse(),a}u(O,"extractStatementsUsingAutocomplete");export{u as a,U as b,K as c,g as d,Q as e,W as f,X as g,L as h,Y as i,d as j,F as k,ie as l};
