Browse Source

HUE-7695 [editor] Only mark syntax errors in the active statement

Johan Ahlen 8 years ago
parent
commit
6553557403

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

@@ -3801,9 +3801,6 @@
         }).fail(promise.reject);
       } else if (token.parseLocation.identifierChain && token.parseLocation.identifierChain.length > 0) {
         // fetch the parent
-        // TODO: Fetch the parents parent first to see if it actually exists to prevent a bunch of failing calls when
-        // typing, i.e. SELECT * FROM c| -> SELECT * FROM cu| -> SELECT * FROM cus|
-        // Better yet, don't check tables next to cursor
         return self.fetchAutocompleteDeferred(token.parseLocation.identifierChain.slice(0, token.parseLocation.identifierChain.length - 1));
       } else {
         promise.reject([]);
@@ -3820,10 +3817,6 @@
       var self = this;
       window.clearInterval(verifyThrottle);
       self.clearMarkedErrors('warning');
-      tokens.forEach(function (token) {
-        delete token.notFound;
-        delete token.syntaxError;
-      });
 
       if (self.sqlSyntaxWorkerSub === null) {
         return;
@@ -4051,6 +4044,8 @@
             delete activeTokens.pop().parseLocation;
           }
 
+          var tokensToVerify = [];
+
           e.data.locations.forEach(function (location) {
             if (['statement', 'selectList', 'whereClause', 'limitClause'].indexOf(location.type) !== -1 ||  ((location.type === 'table' || location.type === 'column') && typeof location.identifierChain === 'undefined')) {
               return;
@@ -4074,10 +4069,15 @@
             if (token !== null) {
               token.parseLocation = location;
               activeTokens.push(token);
+              delete token.notFound;
+              delete token.syntaxError;
+              if (location.active) {
+                tokensToVerify.push(token);
+              }
             }
           });
 
-          self.verifyExists(activeTokens, e.data.locations);
+          self.verifyExists(tokensToVerify, e.data.activeStatementLocations);
           huePubSub.publish('editor.active.locations', lastKnownLocations);
         });
       });

+ 5 - 4
desktop/core/src/desktop/templates/ace_sql_location_worker.mako

@@ -32,13 +32,14 @@ importScripts('${ static('desktop/js/sqlFunctions.js') }');
 
   this.throttle = -1;
 
-  this.handleStatement = function (statement, locations, type) {
+  this.handleStatement = function (statement, locations, type, active) {
     // Statement locations come in the message to the worker and are generally more accurate
     locations.push(statement);
     try {
       var sqlParseResult = sqlAutocompleteParser.parseSql(statement.statement + ' ', '', type, false);
       if (sqlParseResult.locations) {
         sqlParseResult.locations.forEach(function (location) {
+          location.active = active;
           // Skip statement locations from the sql parser
           if (location.type !== 'statement') {
             if (location.location.first_line === 1) {
@@ -65,14 +66,14 @@ importScripts('${ static('desktop/js/sqlFunctions.js') }');
         var locations = [];
         var activeStatementLocations = [];
         msg.data.statementDetails.precedingStatements.forEach(function (statement) {
-          this.handleStatement(statement, locations, msg.data.type);
+          this.handleStatement(statement, locations, msg.data.type, false);
         });
         if (msg.data.statementDetails.activeStatement) {
-          this.handleStatement(msg.data.statementDetails.activeStatement, activeStatementLocations, msg.data.type);
+          this.handleStatement(msg.data.statementDetails.activeStatement, activeStatementLocations, msg.data.type, true);
           locations = locations.concat(activeStatementLocations);
         }
         msg.data.statementDetails.followingStatements.forEach(function (statement) {
-          this.handleStatement(statement, locations, msg.data.type);
+          this.handleStatement(statement, locations, msg.data.type, false);
         });
 
         postMessage({