|
| 1 | +import React from 'react'; |
| 2 | +import ReactDOM from 'react-dom'; |
| 3 | +import { IAppInstance, AppRenderer, SlotLocation } from '@alipay/alex'; |
| 4 | +import * as Alex from '@alipay/alex'; |
| 5 | +// import '@alipay/alex/languages/sql'; |
| 6 | +import { isFilesystemReady } from '@alipay/alex-core'; |
| 7 | +import { CompletionItemKind, SqlServiceModule, supportLanguage } from '@alipay/alex-sql-service'; |
| 8 | +import dtSql from '@alipay/alex/extensions/alex.dt-sql'; |
| 9 | + |
| 10 | +(window as any).alex = Alex; |
| 11 | + |
| 12 | +isFilesystemReady().then(() => { |
| 13 | + console.log('filesystem ready'); |
| 14 | +}); |
| 15 | + |
| 16 | +const layoutConfig = { |
| 17 | + [SlotLocation.action]: { |
| 18 | + modules: [''], |
| 19 | + }, |
| 20 | + [SlotLocation.main]: { |
| 21 | + modules: ['@opensumi/ide-editor'], |
| 22 | + }, |
| 23 | +}; |
| 24 | + |
| 25 | +const defaultContent = `SELECT * FROM table`; |
| 26 | + |
| 27 | +const App = () => ( |
| 28 | + <AppRenderer |
| 29 | + onLoad={(app) => { |
| 30 | + window.app = app; |
| 31 | + }} |
| 32 | + appConfig={{ |
| 33 | + plugins: [], |
| 34 | + modules: [ |
| 35 | + SqlServiceModule.Config({ |
| 36 | + onValidation: (ast: any, markers: any) => { |
| 37 | + console.log(ast, markers); |
| 38 | + // const filterMarkers = markers.filter((item, index) => { |
| 39 | + // if (item.message == 'SEMICOLON expected.') { |
| 40 | + // const markerText = editorIns.current.editor.getModel().getValueInRange({ |
| 41 | + // startLineNumber: item.startLineNumber, |
| 42 | + // startColumn: item.startColumn, |
| 43 | + // endLineNumber: item.endLineNumber, |
| 44 | + // endColumn: item.endColumn, |
| 45 | + // }); |
| 46 | + // if (!['by', 'from'].includes(markerText)) { |
| 47 | + // return true; |
| 48 | + // } |
| 49 | + // } |
| 50 | + // }); |
| 51 | + // return filterMarkers; |
| 52 | + return []; |
| 53 | + }, |
| 54 | + onSuggestTables: (keyword, options) => { |
| 55 | + console.log(keyword, options); |
| 56 | + return Promise.resolve([ |
| 57 | + { |
| 58 | + label: 'sample_one_table1', |
| 59 | + type: 'SAMPLE_TYPE_ONE', |
| 60 | + insertText: 'LD.sample_one_table1', |
| 61 | + kind: CompletionItemKind.Method, |
| 62 | + sortText: 'a', |
| 63 | + }, |
| 64 | + ]); |
| 65 | + }, |
| 66 | + options: { |
| 67 | + value: defaultContent, |
| 68 | + language: supportLanguage.ODPSSQL, |
| 69 | + }, |
| 70 | + onChange: (value) => { |
| 71 | + console.log(value); |
| 72 | + }, |
| 73 | + // completionTypes: { |
| 74 | + // KEYWORD: { |
| 75 | + // text: '关键词', |
| 76 | + // kind: CompletionItemKind.Keyword, |
| 77 | + // }, |
| 78 | + // CUSTOM: { |
| 79 | + // text: '手动配置关键词', |
| 80 | + // kind: CompletionItemKind.Keyword, |
| 81 | + // }, |
| 82 | + // }, |
| 83 | + }), |
| 84 | + ], |
| 85 | + extensionMetadata: [dtSql], |
| 86 | + workspaceDir: `sql-service`, |
| 87 | + layoutConfig, |
| 88 | + defaultPreferences: { |
| 89 | + 'general.theme': 'opensumi-light', |
| 90 | + }, |
| 91 | + }} |
| 92 | + runtimeConfig={{ |
| 93 | + biz: 'sql-service', |
| 94 | + scenario: 'ALEX_TEST', |
| 95 | + defaultOpenFile: 'test.sql', |
| 96 | + // unregisterActivityBarExtra: true, |
| 97 | + hideLeftTabBar: true, |
| 98 | + workspace: { |
| 99 | + filesystem: { |
| 100 | + fs: 'FileIndexSystem', |
| 101 | + options: { |
| 102 | + // 初始全量文件索引 |
| 103 | + requestFileIndex() { |
| 104 | + return Promise.resolve({ |
| 105 | + 'main.html': '<div id="root"></div>', |
| 106 | + 'main.css': 'body {}', |
| 107 | + 'main.js': 'console.log("main")', |
| 108 | + 'test.sql': 'SELECT * FROM table', |
| 109 | + }); |
| 110 | + }, |
| 111 | + }, |
| 112 | + }, |
| 113 | + }, |
| 114 | + }} |
| 115 | + /> |
| 116 | +); |
| 117 | + |
| 118 | +let key = 0; |
| 119 | +const render = () => ReactDOM.render(<App key={key++} />, document.getElementById('main')); |
| 120 | +render(); |
| 121 | +// for dispose test |
| 122 | +window.reset = (destroy = false) => |
| 123 | + destroy ? ReactDOM.render(<div>destroyed</div>, document.getElementById('main')) : render(); |
| 124 | + |
| 125 | +declare global { |
| 126 | + interface Window { |
| 127 | + app: IAppInstance; |
| 128 | + reset(destroyed?: boolean): void; |
| 129 | + } |
| 130 | +} |
0 commit comments