瀏覽代碼

HUE-4031 [editor] Don't suggest non-alpha chars for syntax errors

Johan Ahlen 8 年之前
父節點
當前提交
b537c17

+ 1 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSyntaxParserSpec.js

@@ -74,6 +74,7 @@
       expect(result).toBeTruthy();
       expect(result.loc.first_column).toEqual(10);
       expect(result.loc.last_column).toEqual(14);
+      expect(expectedToStrings(result.expected)).toEqual(['from', 'group', 'order', 'where', 'limit', 'union', 'having']);
     });
 
     it('should find errors for "select * from customers c cultster by awasd asd afd;"', function () {

+ 5 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlParseSupport.js

@@ -1623,7 +1623,8 @@ var SqlParseSupport = (function () {
         parser.yy.error.expected.forEach(function (expected) {
           // Strip away the surrounding ' chars
           expected = expected.substring(1, expected.length - 1);
-          if (!IGNORED_EXPECTED[expected]) {
+          // TODO: Only suggest alphanumeric?
+          if (!IGNORED_EXPECTED[expected] && /[a-z_]+/i.test(expected)) {
             if (expected.length > 0 && expected.indexOf('<') !== 0) {
               weightedExpected.push({
                 text: isLowerCase ? expected.toLowerCase() : expected,
@@ -1638,6 +1639,9 @@ var SqlParseSupport = (function () {
             }
           }
         });
+        if (weightedExpected.length === 0) {
+          return false; // Don't mark it as an error if there are not suggestions
+        }
         weightedExpected.sort(function (a, b) {
           if (a.distance === b.distance) {
             return a.text.localeCompare(b.text);