Skip to content

Commit f97eb9c

Browse files
committed
Use new API for ParseAndCheckDocument
1 parent ca673f3 commit f97eb9c

File tree

2 files changed

+57
-49
lines changed

2 files changed

+57
-49
lines changed

ReSharper.FSharp/src/FSharp/FSharp.Common/src/Checker/FSharpCheckerExtensions.fs

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[<AutoOpen>]
22
module JetBrains.ReSharper.Plugins.FSharp.Checker.FSharpCheckerExtensions
33

4+
#nowarn "57"
5+
46
open System.Threading
57
open System.Threading.Tasks
68
open FSharp.Compiler.CodeAnalysis
@@ -19,13 +21,13 @@ type CheckResults =
1921
| StillRunning of Task<(FSharpParseFileResults * FSharpCheckFileResults) option>
2022

2123
type FSharpChecker with
22-
member internal x.ParseAndCheckDocument(path, source: ISourceText, options, allowStale: bool, opName) =
23-
let version = source.GetHashCode()
24+
member internal x.ParseAndCheckDocument(path, projectSnapshot: FSharpProjectSnapshot, allowStale: bool, opName) =
25+
// let version = source.GetHashCode()
2426

2527
let parseAndCheckFile =
2628
async {
2729
let! parseResults, checkFileAnswer =
28-
x.ParseAndCheckFileInProject(path, version, source, options, userOpName = opName)
30+
x.ParseAndCheckFileInProject(path, projectSnapshot, userOpName = opName)
2931

3032
return
3133
match checkFileAnswer with
@@ -60,28 +62,30 @@ type FSharpChecker with
6062
Some (parseResults, checkResults)
6163
| _ -> None
6264

63-
async {
64-
match x.TryGetRecentCheckResultsForFile(path, options, source) with
65-
| None ->
66-
// No stale results available, wait for fresh results
67-
return! parseAndCheckFile
68-
69-
| Some (parseResults, checkFileResults, cachedVersion) when allowStale && cachedVersion = int64 version ->
70-
// Avoid queueing on the reactor thread by using the recent results
71-
return Some (parseResults, checkFileResults)
72-
73-
| Some (staleParseResults, staleCheckFileResults, _) ->
74-
75-
match! tryGetFreshResultsWithTimeout() with
76-
| Ready x ->
77-
// Fresh results were ready quickly enough
78-
return x
79-
80-
| StillRunning _ when allowStale ->
81-
// Still waiting for fresh results - just use the stale ones for now
82-
return Some (staleParseResults, staleCheckFileResults)
83-
84-
| StillRunning worker ->
85-
return! Async.AwaitTask worker
86-
}
87-
|> map bindParsedInput
65+
map bindParsedInput parseAndCheckFile
66+
// async {
67+
// // TODO: TryGetRecentCheckResultsForFile is missing on the Transparent compiler
68+
// match x.TryGetRecentCheckResultsForFile(path, options, source) with
69+
// | None ->
70+
// // No stale results available, wait for fresh results
71+
// return! parseAndCheckFile
72+
//
73+
// | Some (parseResults, checkFileResults, cachedVersion) when allowStale && cachedVersion = int64 version ->
74+
// // Avoid queueing on the reactor thread by using the recent results
75+
// return Some (parseResults, checkFileResults)
76+
//
77+
// | Some (staleParseResults, staleCheckFileResults, _) ->
78+
//
79+
// match! tryGetFreshResultsWithTimeout() with
80+
// | Ready x ->
81+
// // Fresh results were ready quickly enough
82+
// return x
83+
//
84+
// | StillRunning _ when allowStale ->
85+
// // Still waiting for fresh results - just use the stale ones for now
86+
// return Some (staleParseResults, staleCheckFileResults)
87+
//
88+
// | StillRunning worker ->
89+
// return! Async.AwaitTask worker
90+
// }
91+
// |> map bindParsedInput

ReSharper.FSharp/src/FSharp/FSharp.Common/src/Checker/FcsCheckerService.fs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace rec JetBrains.ReSharper.Plugins.FSharp.Checker
22

3+
#nowarn "57"
4+
35
open System
46
open System.Collections.Generic
57
open System.IO
@@ -38,8 +40,7 @@ module FcsCheckerService =
3840

3941
type FcsProject =
4042
{ OutputPath: VirtualFileSystemPath
41-
ProjectOptions: FSharpProjectOptions
42-
ProjectSnapshot: FSharpProjectSnapshot option
43+
ProjectSnapshot: FSharpProjectSnapshot
4344
ParsingOptions: FSharpParsingOptions
4445
FileIndices: IDictionary<VirtualFileSystemPath, int>
4546
ImplementationFilesWithSignatures: ISet<VirtualFileSystemPath>
@@ -54,23 +55,26 @@ type FcsProject =
5455
tryGetValue path x.FileIndices |> Option.defaultValue -1
5556

5657
member x.TestDump(writer: TextWriter) =
57-
let projectOptions = x.ProjectOptions
58-
59-
writer.WriteLine($"Project file: {projectOptions.ProjectFileName}")
60-
writer.WriteLine($"Stamp: {projectOptions.Stamp}")
61-
writer.WriteLine($"Load time: {projectOptions.LoadTime}")
62-
63-
writer.WriteLine("Source files:")
64-
for sourceFile in projectOptions.SourceFiles do
65-
writer.WriteLine($" {sourceFile}")
66-
67-
writer.WriteLine("Other options:")
68-
for option in projectOptions.OtherOptions do
69-
writer.WriteLine($" {option}")
58+
let projectSnapshot = x.ProjectSnapshot
59+
let (ProjectSnapshot.FSharpProjectIdentifier(projectFileName, _)) = projectSnapshot.Identifier
7060

71-
writer.WriteLine("Referenced projects:")
72-
for referencedProject in projectOptions.ReferencedProjects do
73-
writer.WriteLine($" {referencedProject.OutputFile}")
61+
writer.WriteLine($"Project file: {projectFileName}")
62+
// TODO: the ProjectSnapshot exposes less information than the ProjectOptions
63+
64+
// writer.WriteLine($"Stamp: {projectSnapshot.}")
65+
// writer.WriteLine($"Load time: {projectSnapshot.LoadTime}")
66+
//
67+
// writer.WriteLine("Source files:")
68+
// for sourceFile in projectSnapshot.SourceFiles do
69+
// writer.WriteLine($" {sourceFile}")
70+
//
71+
// writer.WriteLine("Other options:")
72+
// for option in projectSnapshot.OtherOptions do
73+
// writer.WriteLine($" {option}")
74+
//
75+
// writer.WriteLine("Referenced projects:")
76+
// for referencedProject in projectSnapshot.ReferencedProjects do
77+
// writer.WriteLine($" {referencedProject.OutputFile}")
7478

7579
writer.WriteLine()
7680

@@ -172,8 +176,8 @@ type FcsCheckerService(lifetime: Lifetime, logger: ILogger, onSolutionCloseNotif
172176
| None -> None
173177
| Some fcsProject ->
174178

175-
let options = fcsProject.ProjectOptions
176-
if not (fcsProject.IsKnownFile(sourceFile)) && not options.UseScriptResolutionRules then None else
179+
let snapshot = fcsProject.ProjectSnapshot
180+
// if not (fcsProject.IsKnownFile(sourceFile)) && not options.UseScriptResolutionRules then None else
177181

178182
x.FcsProjectProvider.PrepareAssemblyShim(psiModule)
179183

@@ -182,7 +186,7 @@ type FcsCheckerService(lifetime: Lifetime, logger: ILogger, onSolutionCloseNotif
182186
logger.Trace("ParseAndCheckFile: start {0}, {1}", path, opName)
183187

184188
// todo: don't cancel the computation when file didn't change
185-
match x.Checker.ParseAndCheckDocument(path, source, options, allowStaleResults, opName).RunAsTask() with
189+
match x.Checker.ParseAndCheckDocument(path, snapshot, allowStaleResults, opName).RunAsTask() with
186190
| Some (parseResults, checkResults) ->
187191
logger.Trace("ParseAndCheckFile: finish {0}, {1}", path, opName)
188192
Some { ParseResults = parseResults; CheckResults = checkResults }

0 commit comments

Comments
 (0)