@@ -361,46 +361,80 @@ function META:Recompile(path, lol, diagnostics, on_save_path)
361361
362362 local should_analyze = false
363363 local lsp_analyze = not (cfg .lsp and (cfg .lsp .analyze == false or cfg .lsp .parse_only ))
364+ local force_analyze = false
364365
365- if lsp_analyze and path then
366- local ignored = false
367- local project_cfg = self :GetProjectConfig (" get-compiler-config" , path )
366+ if path then
367+ local content = self .TempFiles [path ] or fs .read (path )
368+ force_analyze = content and
369+ (
370+ content :match (" ^%s*%-%-%s*ANALYZE" ) or
371+ content :match (" ^%#%!.-%s*%-%-%s*ANALYZE" )
372+ )
368373
369- if project_cfg and project_cfg .ignorefiles then
370- for _ , pattern in ipairs (project_cfg .ignorefiles ) do
371- if path :find (pattern ) then
372- if path :find (" test_focus%.nlua" ) then
373- self :DebugLog (" not ignoring test_focus.nlua" )
374- else
375- ignored = true
374+ if force_analyze then
375+ should_analyze = true
376+ elseif not lsp_analyze then
377+ should_analyze = false
378+ else
379+ local ignored = false
380+ local project_cfg = self :GetProjectConfig (" get-compiler-config" , path )
381+
382+ if project_cfg and project_cfg .ignorefiles then
383+ for _ , pattern in ipairs (project_cfg .ignorefiles ) do
384+ if path :find (pattern ) then
385+ if path :find (" test_focus%.nlua" ) then
386+ self :DebugLog (" not ignoring test_focus.nlua" )
387+ else
388+ ignored = true
376389
377- break
390+ break
391+ end
378392 end
379393 end
380394 end
381- end
382-
383- if not ignored then
384- local content = self .TempFiles [path ] or fs .read (path )
385395
386- if
387- content and
388- (
389- content :match (" ^%s*%-%-%s*ANALYZE" ) or
390- content :match (" ^%#%!.-%s*%-%-%s*ANALYZE" )
391- )
392- then
393- should_analyze = true
394- elseif path :find (" %.nlua$" ) then
395- should_analyze = true
396+ if not ignored then
397+ if path :find (" %.nlua$" ) then
398+ should_analyze = true
399+ end
396400 end
397401 end
398402 elseif lsp_analyze and cfg .lsp .entry_point then
399403 should_analyze = true
400404 end
401405
402406 if should_analyze then
407+ local restore_import_roots
408+ local restore_should_crawl_untyped_functions
409+
410+ if force_analyze and not lsp_analyze and compiler .SyntaxTree and compiler .SyntaxTree .imports then
411+ local imports = {}
412+
413+ for _ , import_node in ipairs (compiler .SyntaxTree .imports ) do
414+ imports [# imports + 1 ] = {node = import_node , root = import_node .RootStatement }
415+ import_node .RootStatement = false
416+ end
417+
418+ restore_import_roots = function ()
419+ for _ , data in ipairs (imports ) do
420+ data .node .RootStatement = data .root
421+ end
422+ end
423+ end
424+
425+ if force_analyze and not lsp_analyze and cfg .analyzer then
426+ local previous = cfg .analyzer .should_crawl_untyped_functions
427+ cfg .analyzer .should_crawl_untyped_functions = false
428+ restore_should_crawl_untyped_functions = function ()
429+ cfg .analyzer .should_crawl_untyped_functions = previous
430+ end
431+ end
432+
403433 local ok , err = compiler :Analyze (nil , cfg .analyzer )
434+
435+ if restore_import_roots then restore_import_roots () end
436+ if restore_should_crawl_untyped_functions then restore_should_crawl_untyped_functions () end
437+
404438 local name = compiler :GetCode ():GetName ()
405439
406440 if not ok then
0 commit comments