Browse Source

HUE-7288 [editor] Don't check for risks when a statement has syntax errors

Johan Ahlen 8 years ago
parent
commit
753e0d2

+ 3 - 0
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -3637,6 +3637,9 @@
           var suppressedRules = ApiHelper.getInstance().getFromTotalStorage('hue.syntax.checker', 'suppressedRules', {});
           var suppressedRules = ApiHelper.getInstance().getFromTotalStorage('hue.syntax.checker', 'suppressedRules', {});
 
 
           if (e.data.syntaxError && !suppressedRules[self.snippet.id() + e.data.syntaxError.ruleId]) {
           if (e.data.syntaxError && !suppressedRules[self.snippet.id() + e.data.syntaxError.ruleId]) {
+            if (self.snippet.positionStatement() && SqlUtils.locationEquals(e.data.statementLocation, self.snippet.positionStatement().location)) {
+              self.snippet.positionStatement().syntaxError = true;
+            }
             if (hueDebug.showSyntaxParseResult) {
             if (hueDebug.showSyntaxParseResult) {
               console.log(e.data.syntaxError);
               console.log(e.data.syntaxError);
             }
             }

+ 3 - 0
desktop/core/src/desktop/static/desktop/js/sqlUtils.js

@@ -64,6 +64,9 @@ var SqlUtils = (function () {
         return '`' + identifier + '`';
         return '`' + identifier + '`';
       }
       }
       return identifier;
       return identifier;
+    },
+    locationEquals: function (a, b) {
+      return a && b && a.first_line === b.first_line && a.first_column === b.first_column && a.last_line === b.last_line && a.last_column === b.last_column;
     }
     }
   }
   }
 
 

+ 2 - 1
desktop/core/src/desktop/templates/ace_sql_syntax_worker.mako

@@ -61,7 +61,8 @@ importScripts('${ static('desktop/js/autocomplete/sqlSyntaxParser.js') }');
         toAbsoluteLocation(msg.data.statementLocation, syntaxError.loc);
         toAbsoluteLocation(msg.data.statementLocation, syntaxError.loc);
       }
       }
       postMessage({
       postMessage({
-        syntaxError: syntaxError
+        syntaxError: syntaxError,
+        statementLocation: msg.data.statementLocation
       });
       });
     }, 400);
     }, 400);
   }
   }

+ 6 - 0
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -1017,6 +1017,12 @@ var EditorViewModel = (function() {
           return;
           return;
         }
         }
 
 
+        // The syntaxError property is only set if the syntax checker is active and has found an
+        // error, see AceLocationHandler.
+        if (self.positionStatement() && self.positionStatement().syntaxError) {
+          return;
+        }
+
         self.getApiHelper().cancelActiveRequest(lastComplexityRequest);
         self.getApiHelper().cancelActiveRequest(lastComplexityRequest);
 
 
         hueAnalytics.log('notebook', 'get_query_risk');
         hueAnalytics.log('notebook', 'get_query_risk');