@@ -5,6 +5,7 @@ import type { Diagnostic, TextDocument } from 'vscode'
55import { basename } from 'node:path'
66import { config , logger } from '#state'
77import { getPackageInfo } from '#utils/api/package'
8+ import { debounce } from 'perfect-debounce'
89import { computed , useActiveTextEditor , useDocumentText , watch } from 'reactive-vscode'
910import { languages } from 'vscode'
1011import { displayName } from '../../generated-meta'
@@ -44,35 +45,35 @@ export function registerDiagnosticCollection(mapping: Record<string, Extractor |
4445 const dependencies = extractor . getDependenciesInfo ( root )
4546 const diagnostics : Diagnostic [ ] = [ ]
4647
47- await Promise . all (
48- dependencies . map ( async ( dep ) => {
49- try {
50- const pkg = await getPackageInfo ( dep . name )
51- if ( ! pkg )
52- return
48+ const flush = debounce ( ( ) => {
49+ diagnosticCollection . set ( document . uri , [ ...diagnostics ] )
50+ } , 100 )
5351
54- for ( const rule of enabledRules . value ) {
55- const diagnostic = await rule ( dep , pkg )
52+ dependencies . forEach ( async ( dep ) => {
53+ try {
54+ const pkg = await getPackageInfo ( dep . name )
55+ if ( ! pkg )
56+ return
5657
57- if ( diagnostic ) {
58- diagnostics . push ( {
59- source : displayName ,
60- message : diagnostic . message ,
61- severity : diagnostic . severity ,
62- code : diagnostic . code ,
63- range : extractor . getNodeRange ( document , diagnostic . node ) ,
64- } )
65- }
66- }
67- } catch ( err ) {
68- logger . warn ( `Failed to check ${ dep . name } : ${ err } ` )
69- }
70- } ) ,
71- )
58+ enabledRules . value . forEach ( async ( rule ) => {
59+ const diagnostic = await rule ( dep , pkg )
60+
61+ if ( diagnostic ) {
62+ diagnostics . push ( {
63+ source : displayName ,
64+ message : diagnostic . message ,
65+ severity : diagnostic . severity ,
66+ code : diagnostic . code ,
67+ range : extractor . getNodeRange ( document , diagnostic . node ) ,
68+ } )
7269
73- if ( diagnostics . length > 0 )
74- logger . info ( `${ diagnostics . length } diagnostic collected in ${ document . fileName } .` )
75- diagnosticCollection . set ( document . uri , diagnostics )
70+ flush ( )
71+ }
72+ } )
73+ } catch ( err ) {
74+ logger . warn ( `Failed to check ${ dep . name } : ${ err } ` )
75+ }
76+ } )
7677 }
7778
7879 watch ( activeDocumentText , async ( ) => {
0 commit comments