-
Notifications
You must be signed in to change notification settings - Fork 847
[WIP] Added cache invalidation policy when a solution changes #6791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
325bd0d
Clearing caches when a solution changes. Adding an easier way to hand…
TIHan 5bcade8
Add null check for project, rare case it can happen
TIHan 9eb1f83
Clear command line options immediately
TIHan 144a0ac
Unifying single files with normal project cache.
TIHan 8091aa4
Don't reset currentSolution as an empty solution will propagate later.
TIHan 319da9b
Making a message for setSolution
TIHan 8e0bd35
Evicting check file cache results from projects that are invalidated
TIHan b939c99
Move version to the branch it is only used.
TIHan 0fca6b5
Getting everything ready for testing
TIHan 388f6c2
Added cache tests between Roslyn and FCS integration
TIHan ef64412
Invalidating a project had some issues with cross project referencing…
TIHan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
407 changes: 230 additions & 177 deletions
407
vsintegration/src/FSharp.Editor/LanguageService/FSharpProjectOptionsManager.fs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
| namespace Microsoft.VisualStudio.FSharp.Editor.Tests.Roslyn | ||
|
|
||
| open System.IO | ||
| open System.Threading | ||
| open NUnit.Framework | ||
| open Microsoft.VisualStudio.FSharp.Editor | ||
| open Microsoft.CodeAnalysis | ||
| open Microsoft.CodeAnalysis.Text | ||
| open UnitTests.TestLib.LanguageService | ||
|
|
||
| [<TestFixture; Category "Roslyn and FCS Integration"; NonParallelizable>] | ||
| type CacheTests() = | ||
|
|
||
| let testPath = """C:\test\""" | ||
| let testFileName = "TestFile.fs" | ||
| let testFilePath = Path.Combine(testPath, testFileName) | ||
| let testFileSourceText = SourceText.From("""module TestProject.TestFile""") | ||
|
|
||
| let createTestProjectInfo name = | ||
| let projectId = ProjectId.CreateNewId () | ||
| let documentInfos = | ||
| [ | ||
| DocumentInfo.Create (DocumentId.CreateNewId (projectId), testFileName) | ||
| ] | ||
| let dllPath = Path.Combine(testPath, name + ".dll") | ||
| let projectPath = Path.Combine(testPath, name + ".fsproj") | ||
| ProjectInfo.Create (projectId, VersionStamp.Create (), name, name, (* Can't use "F#" due to exception *) "C#", documents = documentInfos, outputFilePath = dllPath, filePath = projectPath) | ||
|
|
||
| let createSolutionInfoWithProjectCount projectCount = | ||
| let testProjectInfos = [ for i = 1 to projectCount do yield createTestProjectInfo ("Test" + string i) ] | ||
| let solutionInfo = SolutionInfo.Create(SolutionId.CreateNewId (), VersionStamp.Create (), projects = testProjectInfos) | ||
| solutionInfo | ||
|
|
||
| let createCompilationEnvWithProjectCount projectCount = | ||
| let solutionInfo = createSolutionInfoWithProjectCount projectCount | ||
| let projectInfos = solutionInfo.Projects | ||
| let workspace = new AdhocWorkspace() | ||
| workspace.AddSolution solutionInfo |> ignore | ||
|
|
||
| let cenv = FSharpCompilationHelpers.createCompilationEnv workspace checker (* enableInMemoryCrossProjectReferences *) true | ||
|
|
||
| // This will go away when HandleCommandLineChanges goes away. | ||
| projectInfos | ||
| |> Seq.iter (fun testProjectInfo -> | ||
| cenv.cpsCommandLineOptions.[testProjectInfo.Id] <- ([|testFilePath|], [||]) | ||
| ) | ||
|
|
||
| (workspace, cenv) | ||
|
|
||
| let basicTest () = | ||
| let (workspace, cenv) = createCompilationEnvWithProjectCount 3 (* we chose 3 because the Checker's default project cache size is 3 by default *) | ||
| let checker = cenv.checker | ||
|
|
||
| checker.StopBackgroundCompile () | ||
| checker.InvalidateAll () | ||
|
|
||
| // We shouldn't have a current solution yet. | ||
| Assert.True (cenv.currentSolution.IsNone) | ||
|
|
||
| let fsharpProjects = | ||
| workspace.CurrentSolution.Projects | ||
| |> Seq.map (fun project -> | ||
| FSharpCompilationHelpers.tryComputeOptions cenv project CancellationToken.None |> Async.RunSynchronously | ||
| ) | ||
| |> List.ofSeq | ||
|
|
||
| // We still don't have a current solution yet. | ||
| Assert.True (cenv.currentSolution.IsNone) | ||
|
|
||
| FSharpCompilationHelpers.setSolution cenv workspace.CurrentSolution | ||
|
|
||
| // We should now have a current solution. | ||
| Assert.True (cenv.currentSolution.IsSome) | ||
|
|
||
| Assert.True (fsharpProjects |> List.forall (fun x -> x.IsSome)) | ||
|
|
||
| let fsharpProjects = fsharpProjects |> List.map (fun x -> snd x.Value) | ||
|
|
||
| Assert.True (fsharpProjects |> List.forall (fun options -> not (checker.ProjectExistsInAnyCache options |> Async.RunSynchronously))) | ||
|
|
||
| fsharpProjects | ||
| |> List.iter (fun options -> | ||
| // We don't care about the results, we only care that it will create an incremental builder for each project when we make a call. | ||
| checker.TryParseAndCheckFileInProject(options, testFilePath, testFileSourceText, "CacheTests") |> Async.RunSynchronously |> ignore | ||
| ) | ||
|
|
||
| // Projects should now exist in the cache. | ||
| Assert.True (fsharpProjects |> List.forall (fun options -> checker.ProjectExistsInAnyCache options |> Async.RunSynchronously)) | ||
| (workspace, cenv) | ||
|
|
||
| [<Test>] | ||
| member __.ProjectCacheRemoveInvdividuallyBySolutionChanges () = | ||
| let (workspace, cenv) = basicTest () | ||
| let checker = cenv.checker | ||
|
|
||
| let mutable solution = workspace.CurrentSolution | ||
| let projectIds = solution.ProjectIds | ||
| let fsharpProjects = | ||
| projectIds | ||
| |> Seq.map (fun projectId -> | ||
| let (_, _, options) = cenv.cache.[projectId] | ||
| options | ||
| ) |> List.ofSeq | ||
|
|
||
| Assert.AreEqual (3, projectIds.Count) | ||
|
|
||
| for i = 0 to projectIds.Count - 1 do | ||
| solution <- solution.RemoveProject projectIds.[i] | ||
| FSharpCompilationHelpers.setSolution cenv solution | ||
|
|
||
| // Remaining projects should still be in the cache. | ||
| for i = i + 1 to projectIds.Count - 1 do | ||
| Assert.True (cenv.cache.ContainsKey projectIds.[i]) | ||
| Assert.True (checker.ProjectExistsInAnyCache fsharpProjects.[i] |> Async.RunSynchronously) | ||
|
|
||
| Assert.False (cenv.cache.ContainsKey projectIds.[i]) | ||
| Assert.False (checker.ProjectExistsInAnyCache fsharpProjects.[i] |> Async.RunSynchronously) | ||
|
|
||
| workspace.Dispose () | ||
|
|
||
| [<Test>] | ||
| member __.ProjectCacheRemoveAllByNewSolution () = | ||
| let (workspace, cenv) = basicTest () | ||
| let checker = cenv.checker | ||
|
|
||
| let solution = workspace.CurrentSolution | ||
| let projectIds = solution.ProjectIds | ||
| let fsharpProjects = | ||
| projectIds | ||
| |> Seq.map (fun projectId -> | ||
| let (_, _, options) = cenv.cache.[projectId] | ||
| options | ||
| ) |> List.ofSeq | ||
|
|
||
| Assert.AreEqual (3, projectIds.Count) | ||
|
|
||
| workspace.ClearSolution () | ||
| let solution = workspace.AddSolution (createSolutionInfoWithProjectCount 0) | ||
|
|
||
| FSharpCompilationHelpers.setSolution cenv solution | ||
|
|
||
| for i = 0 to projectIds.Count - 1 do | ||
| Assert.False (cenv.cache.ContainsKey projectIds.[i]) | ||
| Assert.False (checker.ProjectExistsInAnyCache fsharpProjects.[i] |> Async.RunSynchronously) | ||
|
|
||
| workspace.Dispose () | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.