1- import { AppRenderer , AppRenderer2 , KeepAlive , SlotLocation } from '@alipay/alex' ;
2- import React , { useMemo , useRef , useState } from 'react' ;
1+ import { AppRenderer , SlotLocation } from '@alipay/alex' ;
2+ import React , { useContext , useEffect , useMemo , useRef , useState } from 'react' ;
33import ReactDOM from 'react-dom' ;
44import '@alipay/alex/languages/sql' ;
55import {
@@ -8,32 +8,51 @@ import {
88 supportLanguage ,
99 setMonacoEnvironment ,
1010} from '@alipay/alex-sql-service' ;
11- import SqlPlugin from './sql.plugin' ;
11+ import * as SQLPlugin from './sql.plugin' ;
1212import { Popover , Radio } from 'antd' ;
1313import 'antd/dist/antd.css' ;
1414import odcTheme from '@alipay/alex/extensions/alex.odc-theme' ;
1515import { Button } from '@opensumi/ide-components' ;
1616import { IEditor } from '@opensumi/ide-editor' ;
1717
18+ import { KeepAlive } from './KeepAlive' ;
1819
20+
21+ let tableID = 1 ;
22+
23+ const tableMap = {
24+ 1 : [ ] ,
25+ 2 : [ ]
26+ }
1927export const SQLRender = ( props ) => {
2028
21- const PluginID = props . id
22- const SQLPlugin = useMemo ( ( ) => {
23- return new SqlPlugin ( PluginID ) ;
24- } , [ ] ) ;
2529
26- let tableID = 'table1' ;
30+ const id = useRef ( props . id )
2731
28- const suggestTables = [
29- {
30- label : `sample_two_table_${ tableID } ` ,
31- type : 'SAMPLE_TYPE_TWO' ,
32- insertText : 'LD.sample_one_table1' ,
33- kind : CompletionItemKind . Method ,
34- sortText : 'a' ,
35- } ,
36- ] ;
32+ const suggestTables = useRef ( tableMap ) ;
33+
34+ useEffect ( ( ) => {
35+ id . current = props . id ;
36+
37+ console . log ( 'id' , id )
38+ } , [ props . id ] )
39+
40+ console . log ( 'props' , props ) ;
41+
42+ function changeTables ( ) {
43+ tableID ++ ;
44+ suggestTables . current [ id . current ] = suggestTables . current [ id . current ] . concat ( [
45+ {
46+ label : `sample_one_table_${ tableID } ` ,
47+ type : 'SAMPLE_TYPE_ONE' ,
48+ insertText : 'LD.sample_one_table1' ,
49+ kind : CompletionItemKind . Method ,
50+ sortText : 'a' ,
51+ } ,
52+ ] )
53+ console . log ( 'suggestTables ==> ' , suggestTables )
54+ }
55+ const PluginID = props . id
3756 const layoutConfig = {
3857 [ SlotLocation . main ] : {
3958 modules : [ '@opensumi/ide-editor' ] ,
@@ -45,33 +64,11 @@ export const SQLRender = (props) => {
4564
4665 console . log ( 'render sql ==>' , props )
4766
48-
49- async function addLine ( ) {
50- const editor = ( await SQLPlugin . commands ?. executeCommand ( 'alex.sql.editor' ) ) as IEditor ;
51- editor ?. monacoEditor . trigger ( 'editor' , 'type' , { text : '\n' } ) ;
52- }
53- function format ( ) {
54- SQLPlugin . commands ?. executeCommand ( 'editor.action.formatDocument' ) ;
55- }
56- function openFile ( ) {
57- /** COMMAND alex.sql.open
58- * @param {string } uri - 文件uri
59- * @param {string } content - 文件内容 无内容时创建并注入默认内容
60- */
61- SQLPlugin . commands ?. executeCommand ( 'alex.sql.open' , 'test1.sql' , '默认内容' ) ;
62- }
63- async function getEditor ( ) {
64- const editor = ( await SQLPlugin . commands ?. executeCommand ( 'alex.sql.editor' ) ) as IEditor ;
65- console . log ( editor ?. monacoEditor . getValue ( ) ) ;
66- }
6767
6868 return (
6969 < div style = { { height : '200px' , display : 'flex' } } >
7070 < Button style = { { zIndex : '100' } } onClick = { ( ) => setEditor ( false ) } > 销毁editor</ Button >
71- < Button style = { { zIndex : '100' } } onClick = { ( ) => format ( ) } > 格式化</ Button >
72- < Button style = { { zIndex : '100' } } onClick = { ( ) => addLine ( ) } > 添加行</ Button >
73- < Button style = { { zIndex : '100' } } onClick = { ( ) => openFile ( ) } > 打开文件</ Button >
74- < Button style = { { zIndex : '100' } } onClick = { ( ) => getEditor ( ) } > 获取当前内容</ Button >
71+ < Button onClick = { ( ) => changeTables ( ) } > change suggest Tables</ Button >
7572
7673 { editor && (
7774 < div style = { { border : '2px solid red' , zIndex : '10' , width : '100%' } } >
@@ -119,8 +116,8 @@ export const SQLRender = (props) => {
119116 } ,
120117 ] ,
121118 onSuggestTables : ( keyword , options ) => {
122- console . log ( 'suggest' , keyword , options , suggestTables ) ;
123- return suggestTables ;
119+ console . log ( 'suggest' , keyword , options , suggestTables , id ) ;
120+ return suggestTables . current [ id . current ] ;
124121 } ,
125122 onSuggestFields : ( prefix , options ) => {
126123 console . log ( 'files' , prefix , options ) ;
@@ -210,7 +207,7 @@ export const SQLRender = (props) => {
210207 } ) ,
211208 ] ,
212209 extensionMetadata : [ odcTheme ] ,
213- workspaceDir : `sql-service- ${ PluginID } ` ,
210+ workspaceDir : `sql-service` ,
214211 layoutConfig,
215212 defaultPreferences : {
216213 'general.theme' : 'odc-light' ,
@@ -228,7 +225,7 @@ export const SQLRender = (props) => {
228225 biz : 'sql-service' ,
229226 // hideEditorTab: true,
230227 scenario : 'ALEX_TEST' ,
231- defaultOpenFile : 'test.sql' ,
228+ // defaultOpenFile: 'test.sql',
232229 hideBreadcrumb : true ,
233230 hideLeftTabBar : true ,
234231 registerKeybindings : [
@@ -244,7 +241,8 @@ export const SQLRender = (props) => {
244241 // 初始全量文件索引
245242 requestFileIndex ( ) {
246243 return Promise . resolve ( {
247- 'test.sql' : 'select * from' ,
244+ 'test_uri1/test.sql' : 'select * from 111' ,
245+ 'test_uri2/test.sql' : 'select * from 222' ,
248246 } ) ;
249247 } ,
250248 } ,
0 commit comments