@@ -555,15 +555,11 @@ function m.compileStateThen(state, file)
555555end
556556
557557--- @param uri uri
558- --- @param async boolean ?
559- --- @return parser.state ?
560- function m .compileState (uri , async )
558+ --- @return boolean
559+ function m .checkPreload (uri )
561560 local file = m .fileMap [uri ]
562561 if not file then
563- return
564- end
565- if file .state then
566- return file .state
562+ return false
567563 end
568564 local ws = require ' workspace'
569565 local client = require ' client'
@@ -588,7 +584,22 @@ function m.compileState(uri, async)
588584 client .logMessage (' Info' , message )
589585 end
590586 end
591- return nil
587+ return false
588+ end
589+ return true
590+ end
591+
592+ --- @param uri uri
593+ --- @param callback fun ( state : parser.state ?)
594+ function m .compileStateAsync (uri , callback )
595+ local file = m .fileMap [uri ]
596+ if not file then
597+ callback (nil )
598+ return
599+ end
600+ if file .state then
601+ callback (file .state )
602+ return
592603 end
593604
594605 --- @type brave.param.compile.options
@@ -598,27 +609,50 @@ function m.compileState(uri, async)
598609 nonstandardSymbol = util .arrayToHash (config .get (uri , ' Lua.runtime.nonstandardSymbol' )),
599610 }
600611
601- if async then
602- --- @type brave.param.compile
603- local params = {
604- uri = uri ,
605- text = file .text ,
606- mode = ' Lua' ,
607- version = config .get (uri , ' Lua.runtime.version' ),
608- options = options
609- }
610- pub .task (' compile' , params , function (result )
611- if file .text ~= params .text then
612- return
613- end
614- if not result .state then
615- log .error (' Compile failed:' , uri , result .err )
616- return
617- end
618- m .compileStateThen (result .state , file )
619- end )
612+ --- @type brave.param.compile
613+ local params = {
614+ uri = uri ,
615+ text = file .text ,
616+ mode = ' Lua' ,
617+ version = config .get (uri , ' Lua.runtime.version' ),
618+ options = options
619+ }
620+ pub .task (' compile' , params , function (result )
621+ if file .text ~= params .text then
622+ return
623+ end
624+ if not result .state then
625+ log .error (' Compile failed:' , uri , result .err )
626+ callback (nil )
627+ return
628+ end
629+ m .compileStateThen (result .state , file )
630+ callback (result .state )
631+ end )
632+ end
633+
634+ --- @param uri uri
635+ --- @return parser.state ?
636+ function m .compileState (uri )
637+ local file = m .fileMap [uri ]
638+ if not file then
639+ return
640+ end
641+ if file .state then
642+ return file .state
643+ end
644+ if not m .checkPreload (uri ) then
645+ return
620646 end
621647
648+ --- @type brave.param.compile.options
649+ local options = {
650+ special = config .get (uri , ' Lua.runtime.special' ),
651+ unicodeName = config .get (uri , ' Lua.runtime.unicodeName' ),
652+ nonstandardSymbol = util .arrayToHash (config .get (uri , ' Lua.runtime.nonstandardSymbol' )),
653+ }
654+
655+ local ws = require ' workspace'
622656 local prog <close> = progress .create (uri , lang .script .WINDOW_COMPILING , 0.5 )
623657 prog :setMessage (ws .getRelativePath (uri ))
624658 local clock = os.clock ()
0 commit comments