Browse Source

HUE-4031 [editor] Mark trailing non expected tokens as errors

Johan Ahlen 8 years ago
parent
commit
dd50287

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

@@ -99,6 +99,12 @@
       expect(expectedToStrings(result.expected)).toEqual(['select', 'set', 'alter', 'insert', 'create', 'show', 'use', 'drop', 'from', 'truncate', 'update', 'with']);
       expect(expectedToStrings(result.expected)).toEqual(['select', 'set', 'alter', 'insert', 'create', 'show', 'use', 'drop', 'from', 'truncate', 'update', 'with']);
     });
     });
 
 
+    it('should suggest expected that the statement should end for "use somedb extrastuff "', function() {
+      var result = sqlSyntaxParser.parseSyntax('use somedb extrastuff  ', '');
+      expect(result).toBeTruthy();
+      expect(result.expectedStatementEnd).toBeTruthy();
+    });
+
     it('should find errors for "select * from sample_07 where and\\n\\nselect unknownCol from sample_07;"', function () {
     it('should find errors for "select * from sample_07 where and\\n\\nselect unknownCol from sample_07;"', function () {
       var result = sqlSyntaxParser.parseSyntax('select * from sample_07 where and\n\nselect unknownCol from sample_07;', '', 'hive', false);
       var result = sqlSyntaxParser.parseSyntax('select * from sample_07 where and\n\nselect unknownCol from sample_07;', '', 'hive', false);
       expect(result).toBeTruthy();
       expect(result).toBeTruthy();

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

@@ -1626,6 +1626,12 @@ var SqlParseSupport = (function () {
         var addedExpected = {};
         var addedExpected = {};
 
 
         var isLowerCase = parser.yy.caseDetermined && parser.yy.lowerCase || parser.yy.error.text.toLowerCase() === parser.yy.error.text;
         var isLowerCase = parser.yy.caseDetermined && parser.yy.lowerCase || parser.yy.error.text.toLowerCase() === parser.yy.error.text;
+
+        if (parser.yy.error.expected.length == 2 && parser.yy.error.expected.indexOf('\';\'') !== -1 && parser.yy.error.expected.indexOf('\'EOF\'') !== -1) {
+          parser.yy.error.expected = [];
+          parser.yy.error.expectedStatementEnd = true;
+          return parser.yy.error;
+        }
         parser.yy.error.expected.forEach(function (expected) {
         parser.yy.error.expected.forEach(function (expected) {
           // Strip away the surrounding ' chars
           // Strip away the surrounding ' chars
           expected = expected.substring(1, expected.length - 1);
           expected = expected.substring(1, expected.length - 1);

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

@@ -4232,9 +4232,16 @@
                 tooltipTimeout = window.setTimeout(function () {
                 tooltipTimeout = window.setTimeout(function () {
                   // TODO: i18n
                   // TODO: i18n
                   if (token.syntaxError) {
                   if (token.syntaxError) {
-                    var tooltipText = 'Did you mean "' + token.syntaxError.expected[0].text + '"?';
-                    var endCoordinates = editor.renderer.textToScreenCoordinates(pointerPosition.row, token.start);
-                    contextTooltip.show(tooltipText, endCoordinates.pageX, endCoordinates.pageY + editor.renderer.lineHeight + 3);
+                    var tooltipText;
+                    if (token.syntaxError.expected.length > 0) {
+                      tooltipText = SyntaxCheckerGlobals.i18n.didYouMean + ' "' + token.syntaxError.expected[0].text + '"?';
+                    } else if (token.syntaxError.expectedStatementEnd) {
+                      tooltipText = SyntaxCheckerGlobals.i18n.expectedStatementEnd;
+                    }
+                    if (tooltipText) {
+                      var endCoordinates = editor.renderer.textToScreenCoordinates(pointerPosition.row, token.start);
+                      contextTooltip.show(tooltipText, endCoordinates.pageX, endCoordinates.pageY + editor.renderer.lineHeight + 3);
+                    }
                   }
                   }
                 }, 500);
                 }, 500);
               } else {
               } else {

+ 9 - 2
desktop/core/src/desktop/templates/common_header_footer_components.mako

@@ -98,6 +98,13 @@ from metadata.conf import has_optimizer, OPTIMIZER
       'query-distcp': '${_('DistCp Job')}'
       'query-distcp': '${_('DistCp Job')}'
     };
     };
 
 
+    var SyntaxCheckerGlobals = {
+      i18n: {
+        didYouMean: '${_('Did you mean')}',
+        expectedStatementEnd: '${_('Expected end of statement')}'
+      }
+    };
+
     // jHue plugins global configuration
     // jHue plugins global configuration
     jHueFileChooserGlobals = {
     jHueFileChooserGlobals = {
       labels: {
       labels: {
@@ -149,7 +156,7 @@ from metadata.conf import has_optimizer, OPTIMIZER
       i18n: {
       i18n: {
         cancelUpload: '${ _('Cancel upload') }',
         cancelUpload: '${ _('Cancel upload') }',
         uploadCanceled: '${ _('The upload has been canceled') }',
         uploadCanceled: '${ _('The upload has been canceled') }',
-        uploadSucceeded: '${ _('uploaded successfully') }',
+        uploadSucceeded: '${ _('uploaded successfully') }'
       }
       }
     };
     };
 
 
@@ -159,7 +166,7 @@ from metadata.conf import has_optimizer, OPTIMIZER
         errorRefreshingTableStats: '${_('An error occurred refreshing the table stats. Please try again.')}',
         errorRefreshingTableStats: '${_('An error occurred refreshing the table stats. Please try again.')}',
         errorLoadingDatabases: '${ _('There was a problem loading the databases. Please try again.') }',
         errorLoadingDatabases: '${ _('There was a problem loading the databases. Please try again.') }',
         errorLoadingTablePreview: '${ _('There was a problem loading the table preview. Please try again.') }'
         errorLoadingTablePreview: '${ _('There was a problem loading the table preview. Please try again.') }'
-      },
+      }
     };
     };
 
 
     AutocompleterGlobals = {
     AutocompleterGlobals = {