@@ -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 >
0 commit comments