?
Path : /home/admin/public_html/old/media/editors/codemirror/addon/hint/ |
Current File : /home/admin/public_html/old/media/editors/codemirror/addon/hint/sql-hint.min.js |
!function(a){"object"==typeof exports&&"object"==typeof module?a(require("../../lib/codemirror"),require("../../mode/sql/sql")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","../../mode/sql/sql"],a):a(CodeMirror)}(function(a){"use strict";function b(b){var c=b.doc.modeOption;return"sql"===c&&(c="text/x-sql"),a.resolveMode(c).keywords}function c(a){return"string"==typeof a?a:a.text}function d(a,b){if(!a.slice)return a[b];for(var d=a.length-1;d>=0;d--)if(c(a[d])==b)return a[d]}function e(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b}function f(a,b){var d=a.length,e=c(b).substr(0,d);return a.toUpperCase()===e.toUpperCase()}function g(a,b,c,d){for(var e in c)c.hasOwnProperty(e)&&(c.slice&&(e=c[e]),f(b,e)&&a.push(d(e)))}function h(a){return"."==a.charAt(0)&&(a=a.substr(1)),a.replace(/`/g,"")}function i(a){for(var b=c(a).split("."),d=0;d<b.length;d++)b[d]="`"+b[d]+"`";var f=b.join(".");return"string"==typeof a?f:(a=e(a),a.text=f,a)}function j(a,b,c,f){for(var j=!1,k=[],l=b.start,m=!0;m;)m="."==b.string.charAt(0),j=j||"`"==b.string.charAt(0),l=b.start,k.unshift(h(b.string)),b=f.getTokenAt(s(a.line,b.start)),"."==b.string&&(m=!0,b=f.getTokenAt(s(a.line,b.start)));var q=k.join(".");g(c,q,o,function(a){return j?i(a):a}),g(c,q,p,function(a){return j?i(a):a}),q=k.pop();var r=k.join("."),t=!1,u=r;if(!d(o,r)){var v=r;r=n(r,f),r!==v&&(t=!0)}var w=d(o,r);return w&&w.columns&&(w=w.columns),w&&g(c,q,w,function(a){if("string"==typeof a){var b=r;1==t&&(b=u),a=b+"."+a}else a=e(a),a.text=r+"."+a.text;return j?i(a):a}),l}function k(a,b){if(a)for(var c=/[,;]/g,d=a.split(" "),e=0;e<d.length;e++)b(d[e]?d[e].replace(c,""):"")}function l(a){return a.line+a.ch/Math.pow(10,6)}function m(a){return s(Math.floor(a),+a.toString().split(".").pop())}function n(a,b){for(var c=b.doc,e=c.getValue(),f=a.toUpperCase(),g="",h="",i=[],j={start:s(0,0),end:s(b.lastLine(),b.getLineHandle(b.lastLine()).length)},n=e.indexOf(r.QUERY_DIV);-1!=n;)i.push(c.posFromIndex(n)),n=e.indexOf(r.QUERY_DIV,n+1);i.unshift(s(0,0)),i.push(s(b.lastLine(),b.getLineHandle(b.lastLine()).text.length));for(var p=0,q=l(b.getCursor()),t=0;t<i.length;t++){var u=l(i[t]);if(q>p&&u>=q){j={start:m(p),end:m(u)};break}p=u}for(var v=c.getRange(j.start,j.end,!1),t=0;t<v.length;t++){var w=v[t];if(k(w,function(a){var b=a.toUpperCase();b===f&&d(o,g)&&(h=g),b!==r.ALIAS_KEYWORD&&(g=a)}),h)break}return h}var o,p,q,r={QUERY_DIV:";",ALIAS_KEYWORD:"AS"},s=a.Pos;a.registerHelper("hint","sql",function(a,c){o=c&&c.tables||{};var e=c&&c.defaultTable,f=c&&c.disableKeywords;p=e&&d(o,e),q=q||b(a),e&&!p&&(p=n(e,a)),p=p||[],p.columns&&(p=p.columns);var h,i,k,l=a.getCursor(),m=[],r=a.getTokenAt(l);return r.end>l.ch&&(r.end=l.ch,r.string=r.string.slice(0,l.ch-r.start)),r.string.match(/^[.`\w@]\w*$/)?(k=r.string,h=r.start,i=r.end):(h=i=l.ch,k=""),"."==k.charAt(0)||"`"==k.charAt(0)?h=j(l,r,m,a):(g(m,k,o,function(a){return a}),g(m,k,p,function(a){return a}),f||g(m,k,q,function(a){return a.toUpperCase()})),{list:m,from:s(l.line,h),to:s(l.line,i)}})});