Skip to content

Commit 46b2d0a

Browse files
author
guqiankun.gqk
committed
chore: 修改 open 命令调用
1 parent ecd78e5 commit 46b2d0a

4 files changed

Lines changed: 29 additions & 202 deletions

File tree

packages/integrations/src/sql/index.tsx

Lines changed: 5 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,13 @@ const App = () => {
7979
editor?.monacoEditor.trigger('editor', 'type', { text: '\n' });
8080
}
8181

82-
function openFile() {
82+
async function openFile() {
8383
/** COMMAND alex.sql.open
8484
* @param {string} uri - 文件uri
8585
* @param {string} content - 文件内容 无内容时创建并注入默认内容
8686
*/
87-
SQLPlugin.api.commands?.executeCommand('alex.sql.open', 'test1.sql', '默认内容');
87+
const result = await SQLPlugin.api.commands?.executeCommand('alex.sql.open', 'test1.sql', '默认内容');
88+
console.log('open',result);
8889
}
8990

9091
async function editor() {
@@ -123,7 +124,7 @@ const App = () => {
123124
setCurrent(e.key);
124125
// 每次切换tab 打开对应的文件
125126
if(e.key === '1') {
126-
SQLPlugin.api.commands?.executeCommand('alex.sql.open', 'test_uri1/test.sql', '');
127+
SQLPlugin.api.commands?.executeCommand('alex.sql.open', 'test_uri1/test.sql', '');
127128
}else {
128129
SQLPlugin.api.commands?.executeCommand('alex.sql.open', 'test_uri3/test.sql');
129130
}
@@ -248,10 +249,9 @@ const App = () => {
248249
return (
249250
<div style={{ height: '100%', overflow: 'scroll' }}>
250251
<div style={{ height: '300px' }}>
251-
<div style={{ margin: '20px' }} onContextMenu={()=>{console.log('ContextMenu')}} onClick={()=>console.log('click')}>
252252
<Button onClick={() => format()}>格式化</Button>
253253
<Button onClick={() => addLine()}>添加行</Button>
254-
<Button onClick={() => openFile()}>打开文件</Button>
254+
<Button onClick={async() => await openFile()}>打开文件</Button>
255255
<Button onClick={() => editor()}>获取当前内容</Button>
256256
<Button onClick={() => initMonaco()}>原生编辑器</Button>
257257

@@ -270,186 +270,6 @@ const App = () => {
270270
<SQLRender id={current} visible={current === '2'} />
271271
</div>
272272
</div>
273-
274-
{/* <AppRenderer2
275-
onLoad={(app) => {
276-
window.app = app;
277-
}}
278-
appConfig={{
279-
plugins: [SQLPlugin],
280-
modules: [
281-
SqlServiceModule.Config({
282-
onValidation: (ast: any, markers: any) => {
283-
// console.log(ast, markers);
284-
// const filterMarkers = markers.filter((item, index) => {
285-
// if (item.message == 'SEMICOLON expected.') {
286-
// const markerText = editorIns.current.editor.getModel().getValueInRange({
287-
// startLineNumber: item.startLineNumber,
288-
// startColumn: item.startColumn,
289-
// endLineNumber: item.endLineNumber,
290-
// endColumn: item.endColumn,
291-
// });
292-
// if (!['by', 'from'].includes(markerText)) {
293-
// return true;
294-
// }
295-
// }
296-
// });
297-
return markers;
298-
},
299-
// onWokerLoad: ({language, loadTime}) => {
300-
// // worker 加载完成
301-
// console.log(language, loadTime);
302-
// },
303-
lowerCaseComplete: true,
304-
marks: [
305-
{
306-
message: '测试效果',
307-
startRow: 1,
308-
startCol: 1,
309-
},
310-
],
311-
formatRules: [
312-
// @ts-ignore
313-
{
314-
// regex: /\w/g,
315-
// value: 'select',
316-
},
317-
],
318-
onSuggestTables: (keyword, options) => {
319-
console.log('suggest', keyword, options, suggestTables.current);
320-
return suggestTables.current;
321-
},
322-
onSuggestFields: (prefix, options) => {
323-
console.log('files', prefix, options);
324-
325-
return Promise.resolve([
326-
{
327-
label: 'age',
328-
type: 'SAMPLE_TYPE_ONE',
329-
insertText: 'age',
330-
kind: CompletionItemKind.Field,
331-
sortText: 'b',
332-
},
333-
{
334-
label: 'banana',
335-
type: 'SAMPLE_TYPE_ONE',
336-
insertText: 'banana',
337-
kind: CompletionItemKind.Field,
338-
sortText: 'b',
339-
},
340-
{
341-
label: 'sample_one_table1',
342-
type: 'SAMPLE_TYPE_ONE',
343-
insertText: 'id_test',
344-
kind: CompletionItemKind.Field,
345-
sortText: 'b',
346-
},
347-
]);
348-
},
349-
options: {
350-
language: supportLanguage.ODPSSQL,
351-
disableAsyncItemCache: true,
352-
},
353-
sorter: (type) => {
354-
switch (type) {
355-
case 'TABLEALIAS':
356-
case 'TABLE':
357-
return 'c';
358-
case 'FIELD':
359-
case 'FIELDALIAS':
360-
return 'd';
361-
case 'KEYWORD':
362-
case 'CONSTS':
363-
return 'e';
364-
case 'FUNCTION':
365-
return 'f';
366-
default:
367-
return 'g';
368-
}
369-
},
370-
onChange: (data) => {
371-
// console.log('change',data);
372-
},
373-
completionTypes: {
374-
KEYWORD: {
375-
text: '关键词',
376-
kind: CompletionItemKind.Keyword,
377-
},
378-
CONSTS: {
379-
text: '常量',
380-
kind: CompletionItemKind.Snippet,
381-
},
382-
FUNCTION: {
383-
text: '函数',
384-
kind: CompletionItemKind.Function,
385-
},
386-
TABLE: {
387-
text: '表名',
388-
kind: CompletionItemKind.Method,
389-
},
390-
TABLEALIAS: {
391-
text: '表别名',
392-
kind: CompletionItemKind.Method,
393-
},
394-
SNIPPET: {
395-
text: '代码块',
396-
kind: CompletionItemKind.Snippet,
397-
},
398-
FIELD: {
399-
text: '表字段',
400-
kind: CompletionItemKind.Field,
401-
},
402-
FIELDALIAS: {
403-
text: '表字段别名',
404-
kind: CompletionItemKind.Field,
405-
},
406-
},
407-
}),
408-
],
409-
extensionMetadata: [odcTheme],
410-
workspaceDir: `sql-service`,
411-
layoutConfig,
412-
defaultPreferences: {
413-
'general.theme': 'odc-light',
414-
'application.confirmExit': 'never',
415-
'editor.autoSave': 'afterDelay',
416-
'editor.guides.bracketPairs': false,
417-
'editor.minimap': false,
418-
'editor.autoSaveDelay': 1000,
419-
'editor.fixedOverflowWidgets': true, // widget editor 默认改为 fixed
420-
'files.encoding': 'utf8', // 默认编码
421-
'editor.fontSize': 12,
422-
},
423-
}}
424-
runtimeConfig={{
425-
biz: 'sql-service',
426-
// hideEditorTab: true,
427-
scenario: 'ALEX_TEST',
428-
defaultOpenFile: 'test.sql',
429-
hideBreadcrumb: true,
430-
hideLeftTabBar: true,
431-
registerKeybindings: [
432-
{
433-
command: '',
434-
keybinding: 'f8',
435-
},
436-
],
437-
workspace: {
438-
filesystem: {
439-
fs: 'FileIndexSystem',
440-
options: {
441-
// 初始全量文件索引
442-
requestFileIndex() {
443-
return Promise.resolve({
444-
'test.sql': 'select * from',
445-
});
446-
},
447-
},
448-
},
449-
},
450-
}}
451-
/> */}
452-
</div>
453273
<div style={{ height: '300px', margin: '20px', border: '2px soldi' }} id="monaco">
454274

455275
</div>

packages/sql-service/src/contribution/sql-keybind.contribution.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,19 @@ export class SQLKeybindContribution
6161
execute: (filepath: string, defaultContent?: string) => {
6262
const { workspaceDir } = this.appConfig;
6363
const uri = URI.file(path.join(workspaceDir, filepath));
64-
this.fileService.access(uri.toString()).then((res) => {
64+
return this.fileService.access(uri.toString()).then((res) => {
6565
if (!res) {
66-
this.fileService
66+
return this.fileService
6767
.createFile(uri.toString(), {
6868
content: defaultContent,
6969
})
7070
.then(() => {
71-
this.workbenchEditorService.open(uri);
72-
});
71+
return this.workbenchEditorService.open(uri);
72+
}).catch(err=> {
73+
return false
74+
})
7375
} else {
74-
this.workbenchEditorService.open(uri);
76+
return this.workbenchEditorService.open(uri);
7577
}
7678
});
7779
},
@@ -105,5 +107,6 @@ export class SQLKeybindContribution
105107
// menus.unregisterMenuItem(MenuId.EditorContext, 'EditorContextPeek');
106108
// menus.unregisterMenuItem(MenuId.EditorContext, EDITOR_COMMANDS.FORMAT_DOCUMENT_WITH.id);
107109
// menus.unregisterMenuItem(MenuId.EditorContext, 'editor.action.changeAll');
110+
menus.unregisterMenuId(MenuId.EditorContext)
108111
}
109112
}

packages/sql-service/src/sql-generics/completion-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class CompletionAdapter implements monaco.languages.CompletionItemProvider {
306306
this.options.customizeFieldSuggest(false);
307307
return;
308308
}
309-
309+
// console.log('===> info' , info)
310310
// 是否配置了跳过性能分析上报
311311
const skipCompletionReport = _get(this.options, 'options.skipReport', false);
312312
if (!skipCompletionReport) {

packages/sql-service/src/worker/OBWorker.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import { initialize } from '@opensumi/monaco-editor-core/esm/vs/editor/editor.wo
55
import { TableAuthResponse } from '../tools/validationRules/TableAuth';
66

77
import * as ls from 'vscode-languageserver-types';
8-
import _find from 'lodash/find';
9-
import _filter from 'lodash/filter';
10-
import _flatten from 'lodash/flatten';
11-
import _isEmpty from 'lodash/isEmpty';
12-
import _union from 'lodash/union';
13-
import _uniq from 'lodash/uniq';
14-
import _get from 'lodash/get';
15-
import _orderByget from 'lodash/orderBy';
16-
import _flattenDeep from 'lodash/flattenDeep';
17-
import _findLast from 'lodash/findLast';
18-
import _orderBy from 'lodash/orderBy';
8+
// import _find from 'lodash/find';
9+
// import _filter from 'lodash/filter';
10+
// import _flatten from 'lodash/flatten';
11+
// import _isEmpty from 'lodash/isEmpty';
12+
// import _union from 'lodash/union';
13+
// import _uniq from 'lodash/uniq';
14+
// import _get from 'lodash/get';
15+
// import _orderByget from 'lodash/orderBy';
16+
// import _flattenDeep from 'lodash/flattenDeep';
17+
// import _findLast from 'lodash/findLast';
18+
// import _orderBy from 'lodash/orderBy';
1919
import { validateGroupBy, validateSelectAll, validateTableAuth } from '../tools/validationRules';
2020
import { functionTypeTextMap } from '../sql-functions/odps/definitions';
2121
import { InputStream, CommonTokenStream } from 'antlr4';
@@ -87,6 +87,10 @@ class OBWorker {
8787
console.log(tokens, parser);
8888

8989

90+
console.log('lexer ==> ',Lexer)
91+
console.log('tokens ==> ',tokens)
92+
console.log('parser ==> ',parser)
93+
9094
}
9195

9296

0 commit comments

Comments
 (0)