ソースを参照

[editor] Add an autocomplete parser property on the AceEditor component

Johan Ahlen 5 年 前
コミット
b4c798b814

+ 10 - 2
desktop/core/src/desktop/js/apps/notebook2/components/aceEditor/AceEditor.vue

@@ -19,7 +19,13 @@
 <template>
   <div class="ace-editor-component">
     <div :id="id" ref="editorElement" class="ace-editor" />
-    <ace-autocomplete v-if="editor" :editor="editor" :editor-id="id" :executor="executor" />
+    <ace-autocomplete
+      v-if="editor"
+      :autocomplete-parser="autocompleteParser"
+      :editor="editor"
+      :editor-id="id"
+      :executor="executor"
+    />
   </div>
 </template>
 
@@ -36,7 +42,7 @@
   import { formatSql } from 'apps/notebook2/apiUtils';
   import Executor from 'apps/notebook2/execution/executor';
   import SubscriptionTracker from 'components/utils/SubscriptionTracker';
-  import { IdentifierChainEntry, ParsedLocation } from 'parse/types';
+  import { AutocompleteParser, IdentifierChainEntry, ParsedLocation } from 'parse/types';
   import { EditorInterpreter } from 'types/config';
   import { hueWindow } from 'types/types';
   import huePubSub from 'utils/huePubSub';
@@ -67,6 +73,8 @@
     executor!: Executor;
     @Prop({ required: false, default: () => ({}) })
     aceOptions?: Ace.Options;
+    @Prop({ required: false })
+    autocompleteParser?: AutocompleteParser;
 
     subTracker = new SubscriptionTracker();
     editor: Ace.Editor | null = null;

+ 6 - 1
desktop/core/src/desktop/js/apps/notebook2/components/aceEditor/autocomplete/AceAutocomplete.vue

@@ -81,6 +81,7 @@
 <script lang="ts">
   import { Ace } from 'ext/ace';
   import ace from 'ext/aceHelper';
+  import { AutocompleteParser } from 'parse/types';
   import Vue from 'vue';
   import Component from 'vue-class-component';
   import { Prop } from 'vue-property-decorator';
@@ -129,6 +130,9 @@
     @Prop({ required: false, default: false })
     temporaryOnly?: boolean;
 
+    @Prop({ required: false })
+    autocompleteParser?: AutocompleteParser;
+
     startLayout: DOMRect | null = null;
     startPixelRatio = window.devicePixelRatio;
     left = 0;
@@ -198,7 +202,8 @@
         editorId: this.editorId,
         executor: this.executor,
         editor: this.editor,
-        temporaryOnly: this.temporaryOnly
+        temporaryOnly: this.temporaryOnly,
+        autocompleteParser: this.autocompleteParser
       });
 
       this.subTracker.addDisposable(this.autocompleter);

+ 7 - 2
desktop/core/src/desktop/js/apps/notebook2/components/aceEditor/autocomplete/SqlAutocompleter.ts

@@ -24,7 +24,7 @@ import Executor from 'apps/notebook2/execution/executor';
 import SubscriptionTracker, { Disposable } from 'components/utils/SubscriptionTracker';
 import { Ace } from 'ext/ace';
 import { ParsedSqlStatement } from 'parse/sqlStatementsParser';
-import { AutocompleteParseResult } from 'parse/types';
+import { AutocompleteParser, AutocompleteParseResult } from 'parse/types';
 import { EditorInterpreter } from 'types/config';
 import AutocompleteResults from './AutocompleteResults';
 import huePubSub from 'utils/huePubSub';
@@ -35,6 +35,7 @@ export default class SqlAutocompleter implements Disposable {
   executor: Executor;
   fixedPrefix: () => string;
   fixedPostfix: () => string;
+  autocompleteParser?: AutocompleteParser;
   autocompleteResults: AutocompleteResults;
   editorId: string;
 
@@ -50,12 +51,14 @@ export default class SqlAutocompleter implements Disposable {
     editor: Ace.Editor;
     fixedPrefix?: () => string;
     fixedPostfix?: () => string;
+    autocompleteParser?: AutocompleteParser;
   }) {
     this.editorId = options.editorId;
     this.editor = options.editor;
     this.executor = options.executor;
     this.fixedPrefix = options.fixedPrefix || (() => '');
     this.fixedPostfix = options.fixedPrefix || (() => '');
+    this.autocompleteParser = options.autocompleteParser;
 
     this.autocompleteResults = new AutocompleteResults({
       executor: options.executor,
@@ -111,7 +114,9 @@ export default class SqlAutocompleter implements Disposable {
         }) + this.fixedPostfix();
 
       try {
-        const parser = await sqlParserRepository.getAutocompleter(this.getDialect());
+        const parser =
+          this.autocompleteParser ||
+          (await sqlParserRepository.getAutocompleter(this.getDialect()));
         return parser.parseSql(beforeCursor, afterCursor);
       } catch (err) {
         console.warn(err);