未验证 提交 f5aed4a8 编写于 作者: W Will Smith 提交者: GitHub

Clearing cache of projects that are not in the current solution (#9124)

* Clearing cache of projects that are not in the current solution

* Update LanguageService.fs

* Using seq instead of list

* Fixed build
上级 8a3fa4fd
......@@ -863,6 +863,12 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
if startBackgroundCompileIfAlreadySeen then
bc.CheckProjectInBackground(options, userOpName + ".StartBackgroundCompile"))
member bc.ClearCache(options : FSharpProjectOptions seq, userOpName) =
// This operation can't currently be cancelled nor awaited
reactor.EnqueueOp(userOpName, "ClearCache", String.Empty, fun ctok ->
options
|> Seq.iter (fun options -> incrementalBuildersCache.RemoveAnySimilar(ctok, options)))
member __.NotifyProjectCleaned (options : FSharpProjectOptions, userOpName) =
reactor.EnqueueAndAwaitOpAsync(userOpName, "NotifyProjectCleaned", options.ProjectFileName, fun ctok ->
cancellable {
......@@ -1159,6 +1165,11 @@ type FSharpChecker(legacyReferenceResolver,
let userOpName = defaultArg userOpName "Unknown"
backgroundCompiler.InvalidateConfiguration(options, startBackgroundCompile, userOpName)
/// Clear the internal cache of the given projects.
member __.ClearCache(options: FSharpProjectOptions seq, ?userOpName: string) =
let userOpName = defaultArg userOpName "Unknown"
backgroundCompiler.ClearCache(options, userOpName)
/// This function is called when a project has been cleaned, and thus type providers should be refreshed.
member __.NotifyProjectCleaned(options: FSharpProjectOptions, ?userOpName: string) =
let userOpName = defaultArg userOpName "Unknown"
......
......@@ -359,6 +359,11 @@ type public FSharpChecker =
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
member InvalidateConfiguration: options: FSharpProjectOptions * ?startBackgroundCompileIfAlreadySeen: bool * ?userOpName: string -> unit
/// Clear the internal cache of the given projects.
/// <param name="options">The given project options.</param>
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
member ClearCache: options: FSharpProjectOptions seq * ?userOpName: string -> unit
/// Set the project to be checked in the background. Overrides any previous call to <c>CheckProjectInBackground</c>
member CheckProjectInBackground: options: FSharpProjectOptions * ?userOpName: string -> unit
......
......@@ -81,7 +81,7 @@ type private FSharpProjectOptionsMessage =
| ClearSingleFileOptionsCache of DocumentId
[<Sealed>]
type private FSharpProjectOptionsReactor (_workspace: VisualStudioWorkspace, settings: EditorOptions, _serviceProvider, checkerProvider: FSharpCheckerProvider) =
type private FSharpProjectOptionsReactor (workspace: Workspace, settings: EditorOptions, _serviceProvider, checkerProvider: FSharpCheckerProvider) =
let cancellationTokenSource = new CancellationTokenSource()
// Hack to store command line options from HandleCommandLineChanges
......@@ -208,6 +208,22 @@ type private FSharpProjectOptionsReactor (_workspace: VisualStudioWorkspace, set
if Array.isEmpty projectOptions.SourceFiles then
return None
else
// Clear any caches that need clearing and invalidate the project.
let currentSolution = workspace.CurrentSolution
let projectsToClearCache =
cache
|> Seq.filter (fun pair -> not (currentSolution.ContainsProject pair.Key))
if not (Seq.isEmpty projectsToClearCache) then
projectsToClearCache
|> Seq.iter (fun pair -> cache.Remove pair.Key |> ignore)
let options =
projectsToClearCache
|> Seq.map (fun pair ->
let _, _, projectOptions = pair.Value
projectOptions)
checkerProvider.Checker.ClearCache(options, userOpName = "tryComputeOptions")
checkerProvider.Checker.InvalidateConfiguration(projectOptions, startBackgroundCompileIfAlreadySeen = false, userOpName = "computeOptions")
let parsingOptions, _ = checkerProvider.Checker.GetParsingOptionsFromProjectOptions(projectOptions)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册