Browse Source

[editor] Fix issue where the custom autocompleter is only active when the syntax checker is enabled in Editor v2

Johan Ahlen 4 years ago
parent
commit
873ae4c1f0

+ 17 - 17
desktop/core/src/desktop/js/apps/editor/components/aceEditor/AceEditor.vue

@@ -465,29 +465,29 @@
             el.insertAdjacentElement('beforebegin', doneElem);
             el.insertAdjacentElement('beforebegin', doneElem);
           };
           };
           editor.customMenuOptions.getClearIgnoredSyntaxChecks = () => false;
           editor.customMenuOptions.getClearIgnoredSyntaxChecks = () => false;
+        }
 
 
-          const AceAutocomplete = ace.require('ace/autocomplete').Autocomplete;
+        const AceAutocomplete = ace.require('ace/autocomplete').Autocomplete;
 
 
-          if (!editor.completer) {
-            editor.completer = new AceAutocomplete();
-          }
+        if (!editor.completer) {
+          editor.completer = new AceAutocomplete();
+        }
 
 
-          const isSqlDialect = (<EditorInterpreter>executor.value.connector()).is_sql;
+        const isSqlDialect = (<EditorInterpreter>executor.value.connector()).is_sql;
 
 
-          editor.completer.exactMatch = !isSqlDialect;
+        editor.completer.exactMatch = !isSqlDialect;
 
 
-          const langTools = ace.require('ace/ext/language_tools');
-          langTools.textCompleter.setSqlMode(isSqlDialect);
+        const langTools = ace.require('ace/ext/language_tools');
+        langTools.textCompleter.setSqlMode(isSqlDialect);
 
 
-          if (editor.completers) {
-            editor.completers.length = 0;
-            if (isSqlDialect) {
-              editor.useHueAutocompleter = true;
-            } else {
-              editor.completers.push(langTools.snippetCompleter);
-              editor.completers.push(langTools.textCompleter);
-              editor.completers.push(langTools.keyWordCompleter);
-            }
+        if (editor.completers) {
+          editor.completers.length = 0;
+          if (isSqlDialect) {
+            editor.useHueAutocompleter = true;
+          } else {
+            editor.completers.push(langTools.snippetCompleter);
+            editor.completers.push(langTools.textCompleter);
+            editor.completers.push(langTools.keyWordCompleter);
           }
           }
         }
         }
 
 

+ 11 - 8
desktop/core/src/desktop/js/apps/editor/components/aceEditor/autocomplete/SqlAutocompleter.ts

@@ -16,10 +16,10 @@
 
 
 import {
 import {
   ACTIVE_STATEMENT_CHANGED_EVENT,
   ACTIVE_STATEMENT_CHANGED_EVENT,
-  ActiveStatementChangedEvent,
   GET_ACTIVE_LOCATIONS_EVENT,
   GET_ACTIVE_LOCATIONS_EVENT,
   REFRESH_STATEMENT_LOCATIONS_EVENT
   REFRESH_STATEMENT_LOCATIONS_EVENT
 } from '../AceLocationHandler';
 } from '../AceLocationHandler';
+import { ActiveStatementChangedEventDetails } from '../types';
 import Executor from 'apps/editor/execution/executor';
 import Executor from 'apps/editor/execution/executor';
 import SubscriptionTracker, { Disposable } from 'components/utils/SubscriptionTracker';
 import SubscriptionTracker, { Disposable } from 'components/utils/SubscriptionTracker';
 import { Ace } from 'ext/ace';
 import { Ace } from 'ext/ace';
@@ -70,7 +70,7 @@ export default class SqlAutocompleter implements Disposable {
 
 
     this.subTracker.subscribe(
     this.subTracker.subscribe(
       ACTIVE_STATEMENT_CHANGED_EVENT,
       ACTIVE_STATEMENT_CHANGED_EVENT,
-      (event: ActiveStatementChangedEvent) => {
+      (event: ActiveStatementChangedEventDetails) => {
         if (event.id === this.editorId) {
         if (event.id === this.editorId) {
           this.activeStatement = event.activeStatement;
           this.activeStatement = event.activeStatement;
         }
         }
@@ -137,13 +137,16 @@ export default class SqlAutocompleter implements Disposable {
   async autocomplete(): Promise<AutocompleteParseResult | undefined> {
   async autocomplete(): Promise<AutocompleteParseResult | undefined> {
     let parseResult;
     let parseResult;
     try {
     try {
-      huePubSub.publish(GET_ACTIVE_LOCATIONS_EVENT, (locations: ActiveStatementChangedEvent) => {
-        // This could happen in case the user is editing at the borders of the statement and the locations haven't
-        // been updated yet, in that case we have to force a location update before parsing
-        if (locations.editorChangeTime !== this.editor.lastChangeTime) {
-          huePubSub.publish(REFRESH_STATEMENT_LOCATIONS_EVENT, this.editorId);
+      huePubSub.publish(
+        GET_ACTIVE_LOCATIONS_EVENT,
+        (locations: ActiveStatementChangedEventDetails) => {
+          // This could happen in case the user is editing at the borders of the statement and the locations haven't
+          // been updated yet, in that case we have to force a location update before parsing
+          if (locations.editorChangeTime !== this.editor.lastChangeTime) {
+            huePubSub.publish(REFRESH_STATEMENT_LOCATIONS_EVENT, this.editorId);
+          }
         }
         }
-      });
+      );
 
 
       parseResult = await this.parseActiveStatement();
       parseResult = await this.parseActiveStatement();
     } catch (e) {
     } catch (e) {