@@ -46,6 +46,7 @@ import { python } from '@codemirror/lang-python'
4646import { oneDark } from ' @codemirror/theme-one-dark'
4747import { linter , type Diagnostic } from ' @codemirror/lint'
4848import { loadSharedApi } from ' @/utils/dynamics-api/shared-api'
49+ import debounce from ' lodash/debounce'
4950
5051defineOptions ({ name: ' CodemirrorEditor' })
5152
@@ -86,27 +87,31 @@ function getRangeFromLineAndColumn(state: any, line: number, column: number, end
8687 }
8788}
8889
90+ const asyncLint = debounce (async (doc : string ) => {
91+ const res = await loadSharedApi ({ type: ' tool' , systemType: apiType .value }).postPylint (doc )
92+ return res .data
93+ }, 500 )
94+
8995const regexpLinter = linter (async (view ) => {
9096 const diagnostics: Diagnostic [] = []
91- await loadSharedApi ({ type: ' tool' , systemType: apiType .value })
92- .postPylint (view .state .doc .toString ())
93- .then ((ok : any ) => {
94- ok .data .forEach ((element : any ) => {
95- const range = getRangeFromLineAndColumn (
96- view .state ,
97- element .line ,
98- element .column ,
99- element .endColumn ,
100- )
101-
102- diagnostics .push ({
103- from: range .form ,
104- to: range .to ,
105- severity: element .type ,
106- message: element .message ,
107- })
108- })
97+ const lintResults = await asyncLint (view .state .doc .toString ())
98+ if (! lintResults || lintResults .length === 0 ) {
99+ return diagnostics
100+ }
101+ lintResults .forEach ((element : any ) => {
102+ const range = getRangeFromLineAndColumn (
103+ view .state ,
104+ element .line ,
105+ element .column ,
106+ element .endColumn ,
107+ )
108+ diagnostics .push ({
109+ from: range .form ,
110+ to: range .to ,
111+ severity: element .type ,
112+ message: element .message ,
109113 })
114+ })
110115 return diagnostics
111116})
112117const extensions = [python (), regexpLinter , oneDark ]
0 commit comments