Permalink
Browse files

[pig-hint addon] Remove

It was broken and confused.

Make the mode register a list of completable words instead.

Issue #2324
  • Loading branch information...
1 parent bf8681a commit 370c204c9c43807b61b110656699f13312651ca9 @marijnh marijnh committed Mar 5, 2014
Showing with 2 additions and 125 deletions.
  1. +0 −121 addon/hint/pig-hint.js
  2. +0 −1 doc/compress.html
  3. +0 −3 doc/manual.html
  4. +2 −0 mode/pig/pig.js
View
121 addon/hint/pig-hint.js
@@ -1,121 +0,0 @@
-(function () {
- "use strict";
-
- function forEach(arr, f) {
- for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
- }
-
- function arrayContains(arr, item) {
- if (!Array.prototype.indexOf) {
- var i = arr.length;
- while (i--) {
- if (arr[i] === item) {
- return true;
- }
- }
- return false;
- }
- return arr.indexOf(item) != -1;
- }
-
- function scriptHint(editor, _keywords, getToken) {
- // Find the token at the cursor
- var cur = editor.getCursor(), token = getToken(editor, cur), tprop = token;
- // If it's not a 'word-style' token, ignore the token.
-
- if (!/^[\w$_]*$/.test(token.string)) {
- token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state,
- className: token.string == ":" ? "pig-type" : null};
- }
-
- if (!context) var context = [];
- context.push(tprop);
-
- var completionList = getCompletions(token, context);
- completionList = completionList.sort();
- //prevent autocomplete for last word, instead show dropdown with one word
- if(completionList.length == 1) {
- completionList.push(" ");
- }
-
- return {list: completionList,
- from: CodeMirror.Pos(cur.line, token.start),
- to: CodeMirror.Pos(cur.line, token.end)};
- }
-
- function pigHint(editor) {
- return scriptHint(editor, pigKeywordsU, function (e, cur) {return e.getTokenAt(cur);});
- }
- CodeMirror.pigHint = pigHint; // deprecated
- CodeMirror.registerHelper("hint", "pig", pigHint);
-
- var pigKeywords = "VOID IMPORT RETURNS DEFINE LOAD FILTER FOREACH ORDER CUBE DISTINCT COGROUP "
- + "JOIN CROSS UNION SPLIT INTO IF OTHERWISE ALL AS BY USING INNER OUTER ONSCHEMA PARALLEL "
- + "PARTITION GROUP AND OR NOT GENERATE FLATTEN ASC DESC IS STREAM THROUGH STORE MAPREDUCE "
- + "SHIP CACHE INPUT OUTPUT STDERROR STDIN STDOUT LIMIT SAMPLE LEFT RIGHT FULL EQ GT LT GTE LTE "
- + "NEQ MATCHES TRUE FALSE";
- var pigKeywordsU = pigKeywords.split(" ");
- var pigKeywordsL = pigKeywords.toLowerCase().split(" ");
-
- var pigTypes = "BOOLEAN INT LONG FLOAT DOUBLE CHARARRAY BYTEARRAY BAG TUPLE MAP";
- var pigTypesU = pigTypes.split(" ");
- var pigTypesL = pigTypes.toLowerCase().split(" ");
-
- var pigBuiltins = "ABS ACOS ARITY ASIN ATAN AVG BAGSIZE BINSTORAGE BLOOM BUILDBLOOM CBRT CEIL "
- + "CONCAT COR COS COSH COUNT COUNT_STAR COV CONSTANTSIZE CUBEDIMENSIONS DIFF DISTINCT DOUBLEABS "
- + "DOUBLEAVG DOUBLEBASE DOUBLEMAX DOUBLEMIN DOUBLEROUND DOUBLESUM EXP FLOOR FLOATABS FLOATAVG "
- + "FLOATMAX FLOATMIN FLOATROUND FLOATSUM GENERICINVOKER INDEXOF INTABS INTAVG INTMAX INTMIN "
- + "INTSUM INVOKEFORDOUBLE INVOKEFORFLOAT INVOKEFORINT INVOKEFORLONG INVOKEFORSTRING INVOKER "
- + "ISEMPTY JSONLOADER JSONMETADATA JSONSTORAGE LAST_INDEX_OF LCFIRST LOG LOG10 LOWER LONGABS "
- + "LONGAVG LONGMAX LONGMIN LONGSUM MAX MIN MAPSIZE MONITOREDUDF NONDETERMINISTIC OUTPUTSCHEMA "
- + "PIGSTORAGE PIGSTREAMING RANDOM REGEX_EXTRACT REGEX_EXTRACT_ALL REPLACE ROUND SIN SINH SIZE "
- + "SQRT STRSPLIT SUBSTRING SUM STRINGCONCAT STRINGMAX STRINGMIN STRINGSIZE TAN TANH TOBAG "
- + "TOKENIZE TOMAP TOP TOTUPLE TRIM TEXTLOADER TUPLESIZE UCFIRST UPPER UTF8STORAGECONVERTER";
- var pigBuiltinsU = pigBuiltins.split(" ").join("() ").split(" ");
- var pigBuiltinsL = pigBuiltins.toLowerCase().split(" ").join("() ").split(" ");
- var pigBuiltinsC = ("BagSize BinStorage Bloom BuildBloom ConstantSize CubeDimensions DoubleAbs "
- + "DoubleAvg DoubleBase DoubleMax DoubleMin DoubleRound DoubleSum FloatAbs FloatAvg FloatMax "
- + "FloatMin FloatRound FloatSum GenericInvoker IntAbs IntAvg IntMax IntMin IntSum "
- + "InvokeForDouble InvokeForFloat InvokeForInt InvokeForLong InvokeForString Invoker "
- + "IsEmpty JsonLoader JsonMetadata JsonStorage LongAbs LongAvg LongMax LongMin LongSum MapSize "
- + "MonitoredUDF Nondeterministic OutputSchema PigStorage PigStreaming StringConcat StringMax "
- + "StringMin StringSize TextLoader TupleSize Utf8StorageConverter").split(" ").join("() ").split(" ");
-
- function getCompletions(token, context) {
- var found = [], start = token.string;
- function maybeAdd(str) {
- if (str.lastIndexOf(start, 0) == 0 && !arrayContains(found, str)) found.push(str);
- }
-
- function gatherCompletions(obj) {
- if(obj == ":") {
- forEach(pigTypesL, maybeAdd);
- }
- else {
- forEach(pigBuiltinsU, maybeAdd);
- forEach(pigBuiltinsL, maybeAdd);
- forEach(pigBuiltinsC, maybeAdd);
- forEach(pigTypesU, maybeAdd);
- forEach(pigTypesL, maybeAdd);
- forEach(pigKeywordsU, maybeAdd);
- forEach(pigKeywordsL, maybeAdd);
- }
- }
-
- if (context) {
- // If this is a property, see if it belongs to some object we can
- // find in the current environment.
- var obj = context.pop(), base;
-
- if (obj.type == "variable")
- base = obj.string;
- else if(obj.type == "variable-3")
- base = ":" + obj.string;
-
- while (base != null && context.length)
- base = base[context.pop().string];
- if (base != null) gatherCompletions(base);
- }
- return found;
- }
-})();
View
1 doc/compress.html
@@ -192,7 +192,6 @@
<option value="http://codemirror.net/addon/merge/merge.js">merge.js</option>
<option value="http://codemirror.net/addon/mode/multiplex.js">multiplex.js</option>
<option value="http://codemirror.net/addon/mode/overlay.js">overlay.js</option>
- <option value="http://codemirror.net/addon/hint/pig-hint.js">pig-hint.js</option>
<option value="http://codemirror.net/addon/display/placeholder.js">placeholder.js</option>
<option value="http://codemirror.net/addon/hint/python-hint.js">python-hint.js</option>
<option value="http://codemirror.net/addon/display/rulers.js">rulers.js</option>
View
3 doc/manual.html
@@ -2204,9 +2204,6 @@ <h3 id="api_static">Static properties</h3>
<dt id="addon_sql-hint"><a href="../addon/hint/sql-hint.js"><code>hint/sql-hint.js</code></a></dt>
<dd>A simple SQL hinter. Defines <code>CodeMirror.hint.sql</code>.</dd>
- <dt id="addon_pig-hint"><a href="../addon/hint/pig-hint.js"><code>hint/pig-hint.js</code></a></dt>
- <dd>A simple hinter for <a href="../mode/pig/index.html">Pig Latin</a>. Defines <code>CodeMirror.hint.pig</code>.</dd>
-
<dt id="addon_match-highlighter"><a href="../addon/search/match-highlighter.js"><code>search/match-highlighter.js</code></a></dt>
<dd>Adds a <code>highlightSelectionMatches</code> option that
can be enabled to highlight all instances of a currently
View
2 mode/pig/pig.js
@@ -168,4 +168,6 @@ CodeMirror.defineMode("pig", function(_config, parserConfig) {
keywords: keywords(pKeywords),
types: keywords(pTypes)
});
+
+ CodeMirror.registerHelper("hintWords", "pig", (pBuiltins + pTypes + pKeywords).split(" "));
}());

0 comments on commit 370c204

Please sign in to comment.