@@ -9,7 +9,6 @@ import _ from 'lodash';
9
9
import { parser } from ' dt-sql-parser' ;
10
10
import storage from ' @/js/helper/storage' ;
11
11
import highRiskGrammar from ' ./highRiskGrammar' ;
12
-
13
12
const types = {
14
13
code: {
15
14
theme: ' defaultView' ,
@@ -51,8 +50,9 @@ export default {
51
50
editor: null ,
52
51
editorModel: null ,
53
52
decorations: null ,
54
- parseErrorLine: 0 ,
55
53
isParserClose: false ,
54
+ closeParser: null ,
55
+ openParser: null ,
56
56
};
57
57
},
58
58
computed: {
@@ -86,8 +86,10 @@ export default {
86
86
' value ' : function (newValue , oldValue ) {
87
87
if (this .editor ) {
88
88
this .$emit (' on-operator' );
89
- this .sqlParser (newValue);
90
- if (newValue == this .getValue ()) {
89
+ if (! this .isParserClose ) {
90
+ this .sqlParser (newValue);
91
+ }
92
+ if (newValue == this .getValue () ) {
91
93
return ;
92
94
}
93
95
let readOnly = this .editor .getConfiguration ().readOnly ;
@@ -126,8 +128,9 @@ export default {
126
128
this .editor = monaco .editor .create (this .$el , this .currentConfig );
127
129
this .monaco = monaco;
128
130
this .editorModel = this .editor .getModel ();
131
+ this .isParserClose = !! storage .get (' isParserClose' , ' local' );
129
132
if (this .type !== ' log' ) {
130
- if (this .scriptType !== ' hdfsScript' && ! this .readOnly ) {
133
+ if (this .scriptType !== ' hdfsScript' && ! this .readOnly ) {
131
134
this .addCommands ();
132
135
this .addActions ();
133
136
}
@@ -168,7 +171,6 @@ export default {
168
171
folded sections
169
172
for a certain model when it is connected to an editor instance.
170
173
Once the same model is connected to the same or a different editor instance, editor.restoreViewState can be used to restore the above listed state.
171
-
172
174
There are very many things that influence how rendering occurs:
173
175
the current theme
174
176
the current wrapping settings set on the editor
@@ -253,7 +255,6 @@ export default {
253
255
if (window .monaco ) {
254
256
const monaco = window .monaco ;
255
257
const vm = this ;
256
-
257
258
this .editor .addAction ({
258
259
id: ' editor.action.execute' ,
259
260
label: ' 运行脚本' ,
@@ -265,7 +266,6 @@ export default {
265
266
vm .$emit (' on-run' );
266
267
},
267
268
});
268
-
269
269
this .editor .addAction ({
270
270
id: ' format' ,
271
271
label: ' 格式化' ,
@@ -277,7 +277,6 @@ export default {
277
277
editor .trigger (' anyString' , ' editor.action.formatDocument' );
278
278
},
279
279
});
280
-
281
280
this .editor .addAction ({
282
281
id: ' find' ,
283
282
label: ' 查找' ,
@@ -289,7 +288,6 @@ export default {
289
288
editor .trigger (' find' , ' actions.find' );
290
289
},
291
290
});
292
-
293
291
this .editor .addAction ({
294
292
id: ' replace' ,
295
293
label: ' 替换' ,
@@ -301,7 +299,6 @@ export default {
301
299
editor .trigger (' findReplace' , ' editor.action.startFindReplaceAction' );
302
300
},
303
301
});
304
-
305
302
this .editor .addAction ({
306
303
id: ' commentLine' ,
307
304
label: ' 行注释' ,
@@ -313,7 +310,6 @@ export default {
313
310
editor .trigger (' commentLine' , ' editor.action.commentLine' );
314
311
},
315
312
});
316
-
317
313
this .editor .addAction ({
318
314
id: ' paste' ,
319
315
label: ' 粘贴' ,
@@ -331,7 +327,6 @@ export default {
331
327
return null ;
332
328
},
333
329
});
334
-
335
330
this .editor .addAction ({
336
331
id: ' gotoLine' ,
337
332
label: ' 跳到指定行' ,
@@ -343,11 +338,10 @@ export default {
343
338
editor .trigger (' gotoLine' , ' editor.action.gotoLine' );
344
339
},
345
340
});
346
-
347
341
if (this .language === ' hql' ) {
348
342
// 控制语法检查
349
- const closeParser = this .editor .createContextKey (' closeParser' , true );
350
- const openParser = this .editor .createContextKey (' openParser' , false );
343
+ this . closeParser = this .editor .createContextKey (' closeParser' , ! this . isParserClose );
344
+ this . openParser = this .editor .createContextKey (' openParser' , this . isParserClose );
351
345
this .editor .addAction ({
352
346
id: ' closeParser' ,
353
347
label: ' 关闭语法检查' ,
@@ -358,14 +352,14 @@ export default {
358
352
contextMenuGroupId: ' control' ,
359
353
contextMenuOrder: 2.0 ,
360
354
run (editor ) {
355
+ storage .set (' isParserClose' , true , ' local' );
361
356
vm .isParserClose = true ;
362
357
// 控制右键菜单的显示
363
- openParser .set (true );
364
- closeParser .set (false );
358
+ vm . openParser .set (true );
359
+ vm . closeParser .set (false );
365
360
vm .sqlParser ();
366
361
},
367
362
});
368
-
369
363
this .editor .addAction ({
370
364
id: ' openParser' ,
371
365
label: ' 打开语法检查' ,
@@ -375,28 +369,29 @@ export default {
375
369
contextMenuGroupId: ' control' ,
376
370
contextMenuOrder: 2.1 ,
377
371
run (editor ) {
372
+ storage .set (' isParserClose' , false , ' local' );
378
373
vm .isParserClose = false ;
379
- openParser .set (false );
380
- closeParser .set (true );
374
+ vm . openParser .set (false );
375
+ vm . closeParser .set (true );
381
376
vm .sqlParser ();
382
377
},
383
378
});
384
379
}
385
380
}
386
381
},
387
382
sqlParser: _ .debounce (function (value , cb ) {
388
- const _this = this ;
383
+ const vm = this ;
389
384
let highRiskList = [];
390
- const lang = _this .language ;
391
- const app = _this .application ;
385
+ const lang = vm .language ;
386
+ const app = vm .application ;
392
387
if (lang === ' python' || (app === ' spark' && [' java' , ' hql' ].indexOf (lang) !== - 1 ) || app === ' hive' ) {
393
388
// 高危语法的高亮
394
- highRiskList = _this .setHighRiskGrammar ();
395
- const decora = _this .decorations || [];
389
+ highRiskList = vm .setHighRiskGrammar ();
390
+ const decora = vm .decorations || [];
396
391
let isParseSuccess = true ;
397
392
if (lang === ' hql' ) {
398
- const val = value || _this .value ;
399
- const validParser = _this .isParserClose ? null : parser .parseSyntax (val, ' hive' );
393
+ const val = value || vm .value ;
394
+ const validParser = vm .isParserClose ? null : parser .parseSyntax (val, ' hive' );
400
395
let newDecora = [];
401
396
if (validParser) {
402
397
isParseSuccess = false ;
@@ -426,21 +421,12 @@ export default {
426
421
},
427
422
},
428
423
}];
429
- // 跳到指定行
430
- const line = validParser .loc .first_line ;
431
- if (_this .parseErrorLine !== line) {
432
- _this .parseErrorLine = line;
433
- _this .editor .revealPositionInCenter ({
434
- lineNumber: line,
435
- column: validParser .loc .first_column ,
436
- });
437
- }
438
424
}
439
425
// 第一个参数是旧的,用于清空decorations
440
- _this .decorations = _this .editor .deltaDecorations (decora, newDecora .concat (highRiskList));
441
- _this .$emit (' is-parse-success' , isParseSuccess);
426
+ vm .decorations = vm .editor .deltaDecorations (decora, newDecora .concat (highRiskList));
427
+ vm .$emit (' is-parse-success' , isParseSuccess);
442
428
} else {
443
- _this .decorations = _this .editor .deltaDecorations (decora, highRiskList);
429
+ vm .decorations = vm .editor .deltaDecorations (decora, highRiskList);
444
430
}
445
431
if (cb) {
446
432
cb (isParseSuccess);
@@ -497,4 +483,4 @@ export default {
497
483
},
498
484
};
499
485
</script >
500
- <style lang="scss" src="./index.scss "></style >
486
+ <style lang="scss" src="./index.scss "></style >
0 commit comments