@@ -417,59 +417,65 @@ module internal Extensions =
417417}
418418
419419member this.ParseAndCheckDocument ( filePath : string , textVersionHash : int , sourceText : string , options : FSharpProjectOptions , allowStaleResults : bool ) : Async <( FSharpParseFileResults * Ast.ParsedInput * FSharpCheckFileResults ) option > =
420- let log =
420+ let log x =
421421let file = Path.GetFileName filePath
422- Printf.kprintf( fun s -> Logging.logInfof" [ParseAndCheckDocument(%s )]%s " file s)
423- async {
424- let! freshResults =
425- async {
426- let worker =
422+ Printf.kprintf( fun s -> Logging.logInfof" [ParseAndCheckDocument(%s )]%s " file s) x
423+
424+ let parseAndCheckFile =
425+ async {
426+ use! __= Async.OnCancel( fun _ -> log" parseAndCheckFile has been cancelled" )
427+ log" --> ParseAndCheckFileInProject"
428+ let! parseResults , checkFileAnswer = this.ParseAndCheckFileInProject( filePath, textVersionHash, sourceText, options)
429+ log" <-- ParseAndCheckFileInProject"
430+ return
431+ match checkFileAnswerwith
432+ | FSharpCheckFileAnswer.Aborted->
433+ None
434+ | FSharpCheckFileAnswer.Succeeded( checkFileResults) ->
435+ Some( parseResults, checkFileResults)
436+ }
437+
438+ let tryGetFreshResultsWithTimeout ( timeout : int ) : Async < CheckResults > =
439+ async {
440+ try
441+ log" waiting for result for%d ms" timeout
442+ let! worker = Async.StartChild( parseAndCheckFile, timeout)
443+ log" got result in%d md" timeout
444+ let! result = worker
445+ return Ready result
446+ with: ? TimeoutException ->
447+ log" DID NOT get result in%d ms" timeout
448+ return StillRunning parseAndCheckFile
449+ }
450+
451+ let bindParsedInput ( results : ( FSharpParseFileResults * FSharpCheckFileResults )option ) =
452+ match resultswith
453+ | Some( parseResults, checkResults) ->
454+ match parseResults.ParseTreewith
455+ | Some parsedInput-> Some( parseResults, parsedInput, checkResults)
456+ | None-> None
457+ | None-> None
458+
459+ if allowStaleResultsthen
460+ async {
461+ let! freshResults = tryGetFreshResultsWithTimeout1000
462+
463+ let! results =
464+ match freshResultswith
465+ | Ready x-> async.Return x
466+ | StillRunning worker->
427467async {
428- use! __= Async.OnCancel( fun _ -> log" child has cancelled" )
429- log" --> ParseAndCheckFileInProject"
430- let! parseResults , checkFileAnswer = this.ParseAndCheckFileInProject( filePath, textVersionHash, sourceText, options)
431- log" <-- ParseAndCheckFileInProject"
432- let result =
433- match checkFileAnswerwith
434- | FSharpCheckFileAnswer.Aborted->
435- None
436- | FSharpCheckFileAnswer.Succeeded( checkFileResults) ->
437- Some( parseResults, checkFileResults)
438- return result
468+ match allowStaleResults, this.TryGetRecentCheckResultsForFile( filePath, options) with
469+ | true , Some( parseResults, checkFileResults, _) ->
470+ log" returning stale results"
471+ return Some( parseResults, checkFileResults)
472+ | _ ->
473+ log" stale results cannot be returned, waiting for `worker` to complete"
474+ return ! worker
439475}
440- try
441- log" waiting for result for 1 second"
442- let! worker = Async.StartChild( worker, 1000 )
443- log" got result in 1 second"
444- let! result = worker
445- return Ready result
446- with :? TimeoutException->
447- log" DID NOT get result in 1 second"
448- return StillRunning worker
449- }
450-
451- let! results =
452- match freshResultswith
453- | Ready x-> async.Return x
454- | StillRunning worker->
455- async {
456- match allowStaleResults, this.TryGetRecentCheckResultsForFile( filePath, options) with
457- | true , Some( parseResults, checkFileResults, _) ->
458- log" returning stale results"
459- return Some( parseResults, checkFileResults)
460- | _ ->
461- log" stale results cannot be returned, waiting for `worker` to complete"
462- return ! worker
463- }
464-
465- return
466- match resultswith
467- | Some( parseResults, checkResults) ->
468- match parseResults.ParseTreewith
469- | Some parsedInput-> Some( parseResults, parsedInput, checkResults)
470- | None-> None
471- | None-> None
472- }
476+ return bindParsedInput results
477+ }
478+ else parseAndCheckFile|> Async.map bindParsedInput
473479
474480member this.ParseAndCheckDocument ( document : Document , options : FSharpProjectOptions , allowStaleResults : bool , ? sourceText : SourceText ) : Async <( FSharpParseFileResults * Ast.ParsedInput * FSharpCheckFileResults ) option > =
475481async {