From 0387030a67979c334b03b4b9e37373a8138150c5 Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 15 Feb 2024 15:47:49 +0100 Subject: [PATCH 1/2] Add InvalidateConfiguration endpoint with FSharpProjectSnapshot. --- src/Compiler/Service/BackgroundCompiler.fs | 6 ++++++ src/Compiler/Service/BackgroundCompiler.fsi | 2 ++ src/Compiler/Service/TransparentCompiler.fs | 6 ++++++ src/Compiler/Service/service.fs | 4 ++++ src/Compiler/Service/service.fsi | 7 +++++++ ...rp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl | 1 + ....Compiler.Service.SurfaceArea.netstandard20.release.bsl | 1 + 7 files changed, 27 insertions(+) diff --git a/src/Compiler/Service/BackgroundCompiler.fs b/src/Compiler/Service/BackgroundCompiler.fs index f9f952dde70..54bea5584ad 100644 --- a/src/Compiler/Service/BackgroundCompiler.fs +++ b/src/Compiler/Service/BackgroundCompiler.fs @@ -133,6 +133,8 @@ type internal IBackgroundCompiler = abstract member InvalidateConfiguration: options: FSharpProjectOptions * userOpName: string -> unit + abstract InvalidateConfiguration: projectSnapshot: FSharpProjectSnapshot * userOpName: string -> unit + abstract member NotifyFileChanged: fileName: string * options: FSharpProjectOptions * userOpName: string -> NodeCode abstract member NotifyProjectCleaned: options: FSharpProjectOptions * userOpName: string -> Async @@ -1612,6 +1614,10 @@ type internal BackgroundCompiler member _.InvalidateConfiguration(options: FSharpProjectOptions, userOpName: string) : unit = self.InvalidateConfiguration(options, userOpName) + member this.InvalidateConfiguration(projectSnapshot: FSharpProjectSnapshot, userOpName: string) : unit = + let options = projectSnapshot.ToOptions() + self.InvalidateConfiguration(options, userOpName) + member _.NotifyFileChanged(fileName: string, options: FSharpProjectOptions, userOpName: string) : NodeCode = self.NotifyFileChanged(fileName, options, userOpName) diff --git a/src/Compiler/Service/BackgroundCompiler.fsi b/src/Compiler/Service/BackgroundCompiler.fsi index f3bf3c96ccc..6d63c3b93e9 100644 --- a/src/Compiler/Service/BackgroundCompiler.fsi +++ b/src/Compiler/Service/BackgroundCompiler.fsi @@ -112,6 +112,8 @@ type internal IBackgroundCompiler = abstract InvalidateConfiguration: options: FSharpProjectOptions * userOpName: string -> unit + abstract InvalidateConfiguration: projectSnapshot: FSharpProjectSnapshot * userOpName: string -> unit + abstract NotifyFileChanged: fileName: string * options: FSharpProjectOptions * userOpName: string -> NodeCode abstract NotifyProjectCleaned: options: FSharpProjectOptions * userOpName: string -> Async diff --git a/src/Compiler/Service/TransparentCompiler.fs b/src/Compiler/Service/TransparentCompiler.fs index b117fef1bf6..19d383d00bd 100644 --- a/src/Compiler/Service/TransparentCompiler.fs +++ b/src/Compiler/Service/TransparentCompiler.fs @@ -2136,6 +2136,12 @@ type internal TransparentCompiler member this.InvalidateConfiguration(options: FSharpProjectOptions, userOpName: string) : unit = backgroundCompiler.InvalidateConfiguration(options, userOpName) + member this.InvalidateConfiguration(projectSnapshot: FSharpProjectSnapshot, _userOpName: string) : unit = + let (FSharpProjectIdentifier(projectFileName, outputFileName)) = + projectSnapshot.Identifier + + this.Caches.Clear(Set.singleton (ProjectIdentifier(projectFileName, outputFileName))) + member this.NotifyFileChanged(fileName: string, options: FSharpProjectOptions, userOpName: string) : NodeCode = backgroundCompiler.NotifyFileChanged(fileName, options, userOpName) diff --git a/src/Compiler/Service/service.fs b/src/Compiler/Service/service.fs index 803755ab13f..82b43827e1f 100644 --- a/src/Compiler/Service/service.fs +++ b/src/Compiler/Service/service.fs @@ -372,6 +372,10 @@ type FSharpChecker let userOpName = defaultArg userOpName "Unknown" backgroundCompiler.InvalidateConfiguration(options, userOpName) + member _.InvalidateConfiguration(projectSnapshot: FSharpProjectSnapshot, ?userOpName: string) = + let userOpName = defaultArg userOpName "Unknown" + backgroundCompiler.InvalidateConfiguration(projectSnapshot, userOpName) + /// Clear the internal cache of the given projects. member _.ClearCache(options: seq, ?userOpName: string) = let userOpName = defaultArg userOpName "Unknown" diff --git a/src/Compiler/Service/service.fsi b/src/Compiler/Service/service.fsi index e74249cd604..7ab891cd2ca 100644 --- a/src/Compiler/Service/service.fsi +++ b/src/Compiler/Service/service.fsi @@ -404,6 +404,13 @@ type public FSharpChecker = /// An optional string used for tracing compiler operations associated with this request. member InvalidateConfiguration: options: FSharpProjectOptions * ?userOpName: string -> unit + /// + /// This function is called when the configuration is known to have changed for reasons not encoded in the ProjectOptions. + /// For example, dependent references may have been deleted or created. + /// + [] + member InvalidateConfiguration: projectSnapshot: FSharpProjectSnapshot * ?userOpName: string -> unit + /// Clear the internal cache of the given projects. /// The given project options. /// An optional string used for tracing compiler operations associated with this request. diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl index 0e4eed09edd..f08eb80227d 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl @@ -2086,6 +2086,7 @@ FSharp.Compiler.CodeAnalysis.FSharpChecker: Void ClearCache(System.Collections.G FSharp.Compiler.CodeAnalysis.FSharpChecker: Void ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients() FSharp.Compiler.CodeAnalysis.FSharpChecker: Void InvalidateAll() FSharp.Compiler.CodeAnalysis.FSharpChecker: Void InvalidateConfiguration(FSharp.Compiler.CodeAnalysis.FSharpProjectOptions, Microsoft.FSharp.Core.FSharpOption`1[System.String]) +FSharp.Compiler.CodeAnalysis.FSharpChecker: Void InvalidateConfiguration(FSharpProjectSnapshot, Microsoft.FSharp.Core.FSharpOption`1[System.String]) FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsBindingALambdaAtPosition(FSharp.Compiler.Text.Position) FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsPosContainedInApplication(FSharp.Compiler.Text.Position) FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsPositionContainedInACurriedParameter(FSharp.Compiler.Text.Position) diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl index 0e4eed09edd..f08eb80227d 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl @@ -2086,6 +2086,7 @@ FSharp.Compiler.CodeAnalysis.FSharpChecker: Void ClearCache(System.Collections.G FSharp.Compiler.CodeAnalysis.FSharpChecker: Void ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients() FSharp.Compiler.CodeAnalysis.FSharpChecker: Void InvalidateAll() FSharp.Compiler.CodeAnalysis.FSharpChecker: Void InvalidateConfiguration(FSharp.Compiler.CodeAnalysis.FSharpProjectOptions, Microsoft.FSharp.Core.FSharpOption`1[System.String]) +FSharp.Compiler.CodeAnalysis.FSharpChecker: Void InvalidateConfiguration(FSharpProjectSnapshot, Microsoft.FSharp.Core.FSharpOption`1[System.String]) FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsBindingALambdaAtPosition(FSharp.Compiler.Text.Position) FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsPosContainedInApplication(FSharp.Compiler.Text.Position) FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsPositionContainedInACurriedParameter(FSharp.Compiler.Text.Position) From 4514ba57cec8fb4dc7d5a2f1717c78e0a552703a Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Thu, 15 Feb 2024 18:50:29 +0100 Subject: [PATCH 2/2] Update src/Compiler/Service/service.fsi Co-authored-by: Petr Pokorny --- src/Compiler/Service/service.fsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Service/service.fsi b/src/Compiler/Service/service.fsi index 7ab891cd2ca..1ac5ee53609 100644 --- a/src/Compiler/Service/service.fsi +++ b/src/Compiler/Service/service.fsi @@ -405,7 +405,7 @@ type public FSharpChecker = member InvalidateConfiguration: options: FSharpProjectOptions * ?userOpName: string -> unit /// - /// This function is called when the configuration is known to have changed for reasons not encoded in the ProjectOptions. + /// This function is called when the configuration is known to have changed for reasons not encoded in the projectSnapshot. /// For example, dependent references may have been deleted or created. /// []