浏览代码

HUE-7288 [editor] Don't check for risks for incomplete statements

Johan Ahlen 8 年之前
父节点
当前提交
0cb5c11

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

@@ -26,19 +26,19 @@
       expect(result).toBeFalsy();
     });
 
-    it('should not find errors for "SEL"', function () {
+    it('should report incomplete statement for "SEL"', function () {
       var result = sqlSyntaxParser.parseSyntax('SEL', '');
-      expect(result).toBeFalsy();
+      expect(result.incompleteStatement).toBeTruthy();
     });
 
-    it('should not find errors for "SELECT"', function () {
+    it('should report incomplete statement for "SELECT"', function () {
       var result = sqlSyntaxParser.parseSyntax('SELECT', '');
-      expect(result).toBeFalsy();
+      expect(result.incompleteStatement).toBeTruthy();
     });
 
-    it('should not find errors for "SELECT "', function () {
+    it('should not report incomplete statement for "SELECT "', function () {
       var result = sqlSyntaxParser.parseSyntax('SELECT ', '');
-      expect(result).toBeFalsy();
+      expect(result.incompleteStatement).toBeTruthy();
     });
 
     it('should not find errors for "SELECT *"', function () {
@@ -46,9 +46,9 @@
       expect(result).toBeFalsy();
     });
 
-    it('should not find errors for "SELECT * FR"', function () {
+    it('should not report incomplete statement for "SELECT * FR"', function () {
       var result = sqlSyntaxParser.parseSyntax('SELECT * FR', '');
-      expect(result).toBeFalsy();
+      expect(result.incompleteStatement).toBeTruthy();
     });
 
     it('should find errors for "SLELECT "', function() {

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

@@ -1865,7 +1865,9 @@ var SqlParseSupport = (function () {
           }
         }
         if (weightedExpected.length === 0) {
-          return false; // Don't mark it as an error if there are not suggestions
+          parser.yy.error.expected = [];
+          parser.yy.error.incompleteStatement = true;
+          return parser.yy.error;
         }
         weightedExpected.sort(function (a, b) {
           if (a.distance === b.distance) {
@@ -1875,6 +1877,10 @@ var SqlParseSupport = (function () {
         });
         parser.yy.error.expected = weightedExpected;
         return parser.yy.error;
+      } else if (parser.yy.error) {
+        parser.yy.error.expected = [];
+        parser.yy.error.incompleteStatement = true;
+        return parser.yy.error;
       }
       return false;
     }

+ 12 - 10
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -3643,15 +3643,17 @@
             if (hueDebug.showSyntaxParseResult) {
               console.log(e.data.syntaxError);
             }
-            var token = self.editor.session.getTokenAt(e.data.syntaxError.loc.first_line - 1, e.data.syntaxError.loc.first_column + 1);
-            if (token) {
-              token.syntaxError = e.data.syntaxError;
-              var AceRange = ace.require('ace/range').Range;
-              var range = new AceRange(e.data.syntaxError.loc.first_line - 1, e.data.syntaxError.loc.first_column, e.data.syntaxError.loc.last_line - 1, e.data.syntaxError.loc.first_column + e.data.syntaxError.text.length);
-              var markerId = self.editor.session.addMarker(range, 'hue-ace-syntax-error');
-              self.editor.session.$backMarkers[markerId].token = token;
-            } else {
-              console.warn("couldn't find a token at line: " + (e.data.syntaxError.loc.first_line - 1) + ", column: " + (e.data.syntaxError.loc.first_column + 1));
+            if (!e.data.syntaxError.incompleteStatement) {
+              var token = self.editor.session.getTokenAt(e.data.syntaxError.loc.first_line - 1, e.data.syntaxError.loc.first_column + 1);
+              if (token) {
+                token.syntaxError = e.data.syntaxError;
+                var AceRange = ace.require('ace/range').Range;
+                var range = new AceRange(e.data.syntaxError.loc.first_line - 1, e.data.syntaxError.loc.first_column, e.data.syntaxError.loc.last_line - 1, e.data.syntaxError.loc.first_column + e.data.syntaxError.text.length);
+                var markerId = self.editor.session.addMarker(range, 'hue-ace-syntax-error');
+                self.editor.session.$backMarkers[markerId].token = token;
+              } else {
+                console.warn("couldn't find a token at line: " + (e.data.syntaxError.loc.first_line - 1) + ", column: " + (e.data.syntaxError.loc.first_column + 1));
+              }
             }
           }
         };
@@ -4344,7 +4346,7 @@
                     contextTooltip.show(tooltipText, endCoordinates.pageX, endCoordinates.pageY + editor.renderer.lineHeight + 3);
                   }
                 }, 500);
-              } else if (token !== null && token.syntaxError) {
+              } else if (token !== null && token.syntaxError && !token.syntaxError.incompleteStatement) {
                 tooltipTimeout = window.setTimeout(function () {
                   // TODO: i18n
                   if (token.syntaxError) {