浏览代码

HUE-5826 [editor] Make sure there are no gaps between statement locations reported by the parser

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

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/aceSqlWorker.js

@@ -14,7 +14,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-var version = 12;
+var version = 13;
 importScripts('/static/desktop/js/autocomplete/sql.js?version=' + version);
 importScripts('/static/desktop/js/sqlFunctions.js?version=' + version);
 

+ 15 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sql.js

@@ -6079,6 +6079,21 @@ parser.parseSql = function (beforeCursor, afterCursor, dialect, debug) {
     delete result.error;
   }
 
+  // Adjust all the statement locations to include white space surrounding them
+  var lastStatementLocation = null;
+  result.locations.forEach(function (location) {
+    if (location.type === 'statement') {
+      if (lastStatementLocation === null) {
+        location.location.first_line = 1;
+        location.location.first_column = 1;
+      } else {
+        location.location.first_line = lastStatementLocation.location.last_line;
+        location.location.first_column = lastStatementLocation.location.last_column + 1;
+      }
+      lastStatementLocation = location;
+    }
+  });
+
   return result;
 };/* generated by jison-lex 0.3.4 */
 var lexer = (function(){

+ 15 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sql_support.js

@@ -1394,5 +1394,20 @@ parser.parseSql = function (beforeCursor, afterCursor, dialect, debug) {
     delete result.error;
   }
 
+  // Adjust all the statement locations to include white space surrounding them
+  var lastStatementLocation = null;
+  result.locations.forEach(function (location) {
+    if (location.type === 'statement') {
+      if (lastStatementLocation === null) {
+        location.location.first_line = 1;
+        location.location.first_column = 1;
+      } else {
+        location.location.first_line = lastStatementLocation.location.last_line;
+        location.location.first_column = lastStatementLocation.location.last_column + 1;
+      }
+      lastStatementLocation = location;
+    }
+  });
+
   return result;
 };

+ 2 - 2
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpec.js

@@ -438,7 +438,7 @@
         containsKeywords: ['SELECT'],
         expectedResult: {
           locations: [
-            { type: 'statement', location: { first_line: 2, last_line: 2, first_column: 1, last_column: 25 } },
+            { type: 'statement', location: { first_line: 1, last_line: 2, first_column: 1, last_column: 25 } },
             { type: 'asterisk', location: { first_line: 2, last_line: 2, first_column: 8, last_column: 9 }, tables: [{ identifierChain: [{ name: 'testTable1' }] }] },
             { type: 'table', location: { first_line:2, last_line:2, first_column:15, last_column:25 }, identifierChain: [{ name: 'testTable1' }] }
           ],
@@ -454,7 +454,7 @@
         containsKeywords: ['SELECT'],
         expectedResult: {
           locations: [
-            { type: 'statement', location: { first_line: 4, last_line: 4, first_column: 1, last_column: 25 } },
+            { type: 'statement', location: { first_line: 1, last_line: 4, first_column: 1, last_column: 25 } },
             { type: 'asterisk', location: { first_line: 4, last_line: 4, first_column: 8, last_column: 9 }, tables: [{ identifierChain: [{ name: 'testTable1' }] }] },
             { type: 'table', location: { first_line:4, last_line:4, first_column:15, last_column:25 }, identifierChain: [{ name: 'testTable1' }] }
           ],

+ 2 - 2
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecLocations.js

@@ -270,11 +270,11 @@
             { type: 'column', location: { first_line: 1, last_line: 1, first_column: 56, last_column: 57 }, identifierChain: [{ name: 'testTable' }, { name: 'c' }]},
             { type: 'table', location: { first_line: 1, last_line: 1, first_column: 64, last_column: 66 }, identifierChain: [{ name: 'testTable' }]},
             { type: 'column', location: { first_line: 1, last_line: 1, first_column: 67, last_column: 68 }, identifierChain: [{ name: 'testTable' }, { name: 'd' }]},
-            { type: 'statement', location: { first_line: 2, last_line: 2, first_column: 1, last_column: 33 } },
+            { type: 'statement', location: { first_line: 1, last_line: 2, first_column: 69, last_column: 33 } },
             { type: 'table', location: { first_line: 2, last_line: 2, first_column: 8, last_column: 10 }, identifierChain: [{ name: 'testTable2' }]},
             { type: 'column', location: { first_line: 2, last_line: 2, first_column: 11, last_column: 14 }, identifierChain: [{ name: 'testTable2' }, { name: 'bla' }]},
             { type: 'table', location: { first_line: 2, last_line: 2, first_column: 20, last_column: 30 }, identifierChain: [{ name: 'testTable2' }]},
-            { type: 'statement', location: { first_line: 3, last_line: 3, first_column: 1, last_column: 43 } },
+            { type: 'statement', location: { first_line: 2, last_line: 3, first_column: 34, last_column: 43 } },
             { type: 'asterisk', location: { first_line: 3, last_line: 3, first_column: 8, last_column: 9 }, tables: [{ alias: 't3', identifierChain: [{ name: 'testTable3' }]}, { alias: 't4', identifierChain: [{ name: 'testTable4' }] }] },
             { type: 'table', location: { first_line: 3, last_line: 3, first_column: 15, last_column: 25 }, identifierChain: [{ name: 'testTable3' }]},
             { type: 'table', location: { first_line: 3, last_line: 3, first_column: 30, last_column: 40 }, identifierChain: [{ name: 'testTable4' }]}