Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc8e4e82

Browse files
Vasily KirichenkoVasily Kirichenko
Vasily Kirichenko
authored and
Vasily Kirichenko
committed
refactor ParseAndCheckDocument
1 parentb90cf71 commitc8e4e82

File tree

1 file changed

+56
-50
lines changed

1 file changed

+56
-50
lines changed

‎vsintegration/src/FSharp.Editor/Common/CommonHelpers.fs‎

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -417,59 +417,65 @@ module internal Extensions =
417417
}
418418

419419
memberthis.ParseAndCheckDocument(filePath:string,textVersionHash:int,sourceText:string,options:FSharpProjectOptions,allowStaleResults:bool):Async<(FSharpParseFileResults* Ast.ParsedInput* FSharpCheckFileResults)option>=
420-
letlog=
420+
letlogx=
421421
letfile= Path.GetFileName filePath
422-
Printf.kprintf(fun s-> Logging.logInfof"[ParseAndCheckDocument(%s)]%s" file s)
423-
async{
424-
let!freshResults=
425-
async{
426-
letworker=
422+
Printf.kprintf(fun s-> Logging.logInfof"[ParseAndCheckDocument(%s)]%s" file s) x
423+
424+
letparseAndCheckFile=
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+
lettryGetFreshResultsWithTimeout(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+
letbindParsedInput(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->
427467
async{
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-
letresult=
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

474480
memberthis.ParseAndCheckDocument(document:Document,options:FSharpProjectOptions,allowStaleResults:bool,?sourceText:SourceText):Async<(FSharpParseFileResults* Ast.ParsedInput* FSharpCheckFileResults)option>=
475481
async{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp