Browse Source

HUE-7535 [editor] Fix issue where the syntax checker marks incomplete statements as complete

Johan Ahlen 8 years ago
parent
commit
4ca2264

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

@@ -36,11 +36,31 @@
       expect(result.incompleteStatement).toBeTruthy();
     });
 
-    it('should not report incomplete statement for "SELECT "', function () {
+    it('should report incomplete statement for "SELECT "', function () {
       var result = sqlSyntaxParser.parseSyntax('SELECT ', '');
       expect(result.incompleteStatement).toBeTruthy();
     });
 
+    it('should not report incomplete statement for "SELECT * FROM tbl"', function () {
+      var result = sqlSyntaxParser.parseSyntax('SELECT * FROM tbl', '');
+      expect(result.incompleteStatement).toBeFalsy();
+    });
+
+    it('should not report incomplete statement for "SELECT * FROM tbl LIMIT 1"', function () {
+      var result = sqlSyntaxParser.parseSyntax('SELECT * FROM tbl LIMIT 1', '');
+      expect(result.incompleteStatement).toBeFalsy();
+    });
+
+    it('should report incomplete statement for "SELECT * FROM tbl LIMIT "', function () {
+      var result = sqlSyntaxParser.parseSyntax('SELECT * FROM tbl LIMIT ', '');
+      expect(result.incompleteStatement).toBeTruthy();
+    });
+
+    it('should report incomplete statement for "SELECT * FROM tbl GROUP"', function () {
+      var result = sqlSyntaxParser.parseSyntax('SELECT * FROM tbl GROUP', '');
+      expect(result.incompleteStatement).toBeTruthy();
+    });
+
     it('should not find errors for "SELECT *"', function () {
       var result = sqlSyntaxParser.parseSyntax('SELECT *', '');
       expect(result).toBeFalsy();

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

@@ -1910,6 +1910,7 @@ var SqlParseSupport = (function () {
           return a.distance - b.distance
         });
         parser.yy.error.expected = weightedExpected;
+        parser.yy.error.incompleteStatement = true;
         return parser.yy.error;
       } else if (parser.yy.error) {
         parser.yy.error.expected = [];