Skip to content

Commit ce7f416

Browse files
author
guqiankun.gqk
committed
feat: sql service init
1 parent ed8c77b commit ce7f416

29 files changed

Lines changed: 11886 additions & 5 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ packages/alex/.cloudide
107107
packages/toolkit/extensions
108108
packages/acr/bundle
109109

110+
generated-parser
111+
.antlr
112+
110113
#cloud-ide
111114
.devcontainer.*
112115

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
"ext": "alex ext",
2222
"generate": "node scripts/generate",
2323
"editor": "INTEGRATION=editor npm run dev",
24+
"sql": "INTEGRATION=sql npm run dev",
2425
"acr": "INTEGRATION=antcode-cr npm run dev",
2526
"fs": "INTEGRATION=filesystem npm run dev",
27+
"build:parser": "node scripts/antlr.js",
2628
"build": "node scripts/build",
2729
"bundle": "node scripts/bundle",
2830
"create": "node scripts/create",
@@ -85,7 +87,9 @@
8587
"ts-node": "^9.0.0",
8688
"tslib": "^2.2.0",
8789
"typescript": "^4.2.3",
88-
"urllib": "^2.36.1"
90+
"urllib": "^2.36.1",
91+
"antlr4": "4.7.2",
92+
"shelljs": "^0.8.4"
8993
},
9094
"tnpm": {
9195
"mode": "yarn",

packages/integrations/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"@alipay/alex-i18n": "2.2.4",
2525
"@alipay/alex-lsif-service": "2.2.4",
2626
"@alipay/alex-shared": "2.2.4",
27-
"@ant-design/icons": "~2.1.1",
2827
"ahooks": "2",
2928
"antd": "^4.0.0",
3029
"@ant-design/icons": "^4.0.0",

packages/integrations/src/editor/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ const App = () => {
156156
</Button>
157157
</div>
158158
<div style={{ display: 'flex' }}>
159-
<div style={{ width: '50%', minHeight: 500 }}>
159+
<div style={{ width: '80%', minHeight: 500 }}>
160160
{project ? (
161161
<EditorRenderer
162162
key={`${project}-${key}`}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
}

packages/sql-service/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# sql 语言服务模块
22

33
## 支持基础的SQL语法高亮及自动补全
4+
5+
- db-parser 支持db数据库语法解析
6+
- odps-parser 支持sql语法解析
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Provider, Injectable, Autowired } from '@opensumi/di';
2+
import {
3+
Domain,
4+
BrowserModule,
5+
CommandContribution,
6+
CommandRegistry,
7+
getLanguageId,
8+
Disposable,
9+
CommandService,
10+
ClientAppContribution,
11+
IClientApp,
12+
MaybePromise,
13+
14+
} from '@opensumi/ide-core-browser';
15+
import { CodeModelService } from '@alipay/alex-code-service';
16+
import {} from '@alipay/alex-code-service';
17+
import * as monaco from '@opensumi/monaco-editor-core/esm/vs/editor/editor.api';
18+
import { StandaloneServices } from '@opensumi/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
19+
// import { WorkerAccessor } from './types';
20+
21+
export const ISQLServiceConfig = Symbol('ISQLServiceConfig');
22+
23+
// @Injectable()
24+
// export class SqlServiceConfig {
25+
26+
27+
28+
29+
// }
30+
31+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Provider, Injectable, Autowired } from '@opensumi/di';
2+
import {
3+
Domain,
4+
BrowserModule,
5+
CommandContribution,
6+
CommandRegistry,
7+
getLanguageId,
8+
Disposable,
9+
CommandService,
10+
ClientAppContribution,
11+
IClientApp,
12+
MaybePromise,
13+
14+
} from '@opensumi/ide-core-browser';
15+
import { CodeModelService } from '@alipay/alex-code-service';
16+
import {} from '@alipay/alex-code-service';
17+
import * as monaco from '@opensumi/monaco-editor-core/esm/vs/editor/editor.api';
18+
import { StandaloneServices } from '@opensumi/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
19+
import { ISQLServiceConfig } from './sql-service.configuration';
20+
import { CompletionProviderOptions } from '../types';
21+
// import { WorkerAccessor } from './types';
22+
23+
24+
@Injectable()
25+
@Domain(ClientAppContribution)
26+
export class SqlServiceContribution implements ClientAppContribution {
27+
28+
@Autowired(ISQLServiceConfig)
29+
sqlConfig: CompletionProviderOptions;
30+
31+
32+
onDidStart(app: IClientApp): MaybePromise<void> {
33+
34+
}
35+
36+
37+
// register
38+
39+
40+
41+
}
42+
43+

packages/sql-service/src/index.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,32 @@
1-
export const sqlService = {};
1+
import { Injectable, Provider } from '@opensumi/di';
2+
import { BrowserModule } from '@opensumi/ide-core-browser';
3+
import { extendModule, ModuleConstructor } from '@alipay/alex-core';
4+
import { CompletionProviderOptions, supportLanguage } from './types';
5+
import { ISQLServiceConfig } from './contribution/sql-service.configuration';
6+
import { SqlServiceContribution } from './contribution/sql-service.contribution';
7+
8+
export * from './types';
9+
10+
11+
const defaultConfig: CompletionProviderOptions = {
12+
options: {language: supportLanguage.ODPSSQL},
13+
}
14+
15+
@Injectable()
16+
export class SqlServiceModule extends BrowserModule {
17+
static Config(config: CompletionProviderOptions): ModuleConstructor {
18+
return extendModule({
19+
module: SqlServiceModule,
20+
providers: [
21+
{
22+
token: ISQLServiceConfig,
23+
useValue: config || defaultConfig,
24+
},
25+
],
26+
});
27+
}
28+
29+
providers: Provider[] = [
30+
SqlServiceContribution
31+
];
32+
}

0 commit comments

Comments
 (0)