Skip to content

Commit d43e84a

Browse files
committed
Respect useTransparentCompiler in additional FSharpChecker calls.
1 parent fb7f5be commit d43e84a

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ type FcsCheckerService(lifetime: Lifetime, logger: ILogger, onSolutionCloseNotif
149149
let setting = SettingsUtil.getEntry<FSharpOptions> settingsStore name
150150
settingsStoreLive.GetValueProperty(lifetime, setting, null)
151151

152+
// TODO: double check setting
152153
let useTransparentCompiler = true //(getSettingProperty "UseTransparentCompiler").Value
153154

154155
let checker =
@@ -177,6 +178,7 @@ type FcsCheckerService(lifetime: Lifetime, logger: ILogger, onSolutionCloseNotif
177178
member val AssemblyReaderShim = Unchecked.defaultof<IFcsAssemblyReaderShim> with get, set
178179

179180
member x.Checker = checker.Value
181+
member val UseTransparentCompiler = useTransparentCompiler
180182

181183
member this.AssertFcsAccessThread() =
182184
()
@@ -267,20 +269,34 @@ type FcsCheckerService(lifetime: Lifetime, logger: ILogger, onSolutionCloseNotif
267269
let path = file.GetLocation().FullPath
268270
logger.Trace("TryGetStaleCheckResults: start {0}, {1}", path, opName)
269271

270-
match x.Checker.TryGetRecentCheckResultsForFile(path, options) with
271-
| Some (_, checkResults, _) ->
272+
let recentCheckResults =
273+
if not useTransparentCompiler then
274+
x.Checker.TryGetRecentCheckResultsForFile(path, options)
275+
|> Option.map (fun (_, checkResults, _) -> checkResults)
276+
else
277+
match x.FcsProjectProvider.GetFcsProject(file.PsiModule) with
278+
| None -> None
279+
| Some fcsProject ->
280+
281+
let projectKey = FcsProjectKey.Create(file.PsiModule)
282+
let fcsSnapshotCache = file.GetSolution().GetComponent<FcsSnapshotCache>()
283+
let snapshot = fcsSnapshotCache.GetProjectSnapshot(projectKey, fcsProject.ProjectOptions)
284+
x.Checker.TryGetRecentCheckResultsForFile(path, snapshot)
285+
|> Option.map snd
286+
287+
match recentCheckResults with
288+
| Some checkResults ->
272289
logger.Trace("TryGetStaleCheckResults: finish {0}, {1}", path, opName)
273290
Some checkResults
274-
275291
| _ ->
276292
logger.Trace("TryGetStaleCheckResults: fail {0}, {1}", path, opName)
277293
None
278294

279295
member x.GetCachedScriptOptions(path) =
280296
if checker.IsValueCreated then
297+
checker.Value.GetCachedScriptOptions(path)
298+
else
281299
None
282-
// TODO: checker.Value.GetCachedScriptOptions(path)
283-
else None
284300

285301
member x.InvalidateFcsProject(projectOptions: FSharpProjectOptions, invalidationType: FcsProjectInvalidationType) =
286302
if checker.IsValueCreated then
@@ -290,7 +306,13 @@ type FcsCheckerService(lifetime: Lifetime, logger: ILogger, onSolutionCloseNotif
290306
checker.Value.ClearCache(Seq.singleton projectOptions)
291307
| FcsProjectInvalidationType.Remove ->
292308
logger.Trace("Invalidate FcsProject in FCS: {0}", projectOptions.ProjectFileName)
293-
checker.Value.InvalidateConfiguration(projectOptions)
309+
if useTransparentCompiler then
310+
// InvalidateConfiguration isn't required for the transparent compiler as it works differently.
311+
// InvalidateConfiguration in the BackgroundCompiler will recreate the createBuilderNode.
312+
// This is not required in the TransparentCompiler and so Clearing the cache would be the proper equivalent.
313+
checker.Value.ClearCache(Seq.singleton projectOptions)
314+
else
315+
checker.Value.InvalidateConfiguration(projectOptions)
294316

295317
/// Use with care: returns wrong symbol inside its non-recursive declaration, see dotnet/fsharp#7694.
296318
member x.ResolveNameAtLocation(sourceFile: IPsiSourceFile, names, coords, resolveExpr: bool, opName) =

ReSharper.FSharp/src/FSharp/FSharp.Common/src/ProjectModel/FSharpScriptPsiModuleFactory.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,13 @@ type FSharpScriptPsiModulesProvider(lifetime: Lifetime, solution: ISolution, cha
263263
|> Option.iter (fun psiModule ->
264264
match checkerService.GetCachedScriptOptions(path.FullPath) with
265265
| Some options -> checkerService.InvalidateFcsProject(options, FcsProjectInvalidationType.Remove)
266-
| None -> ()
266+
| None ->
267+
if checkerService.UseTransparentCompiler then
268+
// The transparent compiler always returns GetCachedScriptOptions
269+
// We can easily construct the project identifier (as it is done in GetProjectOptionsFromScript/GetProjectSnapshotFromScript)
270+
// and clear the cache that way.
271+
let projectIdentifier = ProjectSnapshot.FSharpProjectIdentifier($"%s{path.FullPath}.fsproj", "")
272+
checkerService.Checker.ClearCache(Seq.singleton projectIdentifier)
267273

268274
scriptsFromProjectFiles.RemoveValue(path, psiModule) |> ignore
269275
removePsiModule psiModule

0 commit comments

Comments
 (0)