Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1f2f80

Browse files
authored
Fixed multi-targeted projects from invalidating the MruCache on document open/changed (dotnet#4918)
* Handling multi-targeting in FCS by adding an optional ProjectId; handling multi-projects in a better way for LanguageService, making sure we clear it out of the options table* Fixing tests with FSharpProjectOptions type changes* Fixed more tests* Fixed more tests* Fixed more tests* Fixed build
1 parentd245100 commita1f2f80

File tree

24 files changed

+49
-14
lines changed

24 files changed

+49
-14
lines changed

‎fcs/FSharp.Compiler.Service.ProjectCracker/ProjectCracker.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module Utils =
3838

3939
logMap:= Map.add opts.ProjectFile opts.LogOutput!logMap
4040
{ ProjectFileName= opts.ProjectFile
41+
ProjectId= None
4142
SourceFiles= sourceFiles
4243
OtherOptions= otherOptions
4344
ReferencedProjects= referencedProjects()

‎src/fsharp/service/service.fs‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ module internal Parser =
16111611
userOpName:string)=
16121612

16131613
async{
1614-
use _logBlock= Logger.LogBlockMessage(Guid.NewGuid().ToString()) LogCompilerFunctionId.Service_CheckOneFile
1614+
use _logBlock= Logger.LogBlock LogCompilerFunctionId.Service_CheckOneFile
16151615

16161616
match parseResults.ParseTreewith
16171617
// When processing the following cases, we don't need to type-check
@@ -1760,6 +1760,7 @@ type UnresolvedReferencesSet = UnresolvedReferencesSet of UnresolvedAssemblyRefe
17601760
typeFSharpProjectOptions=
17611761
{
17621762
ProjectFileName:string
1763+
ProjectId:string option
17631764
SourceFiles:string[]
17641765
OtherOptions:string[]
17651766
ReferencedProjects:(string* FSharpProjectOptions)[]
@@ -1773,15 +1774,20 @@ type FSharpProjectOptions =
17731774
}
17741775
memberx.ProjectOptions= x.OtherOptions
17751776
/// Whether the two parse options refer to the same project.
1776-
static memberUseSameProjectFileName(options1,options2)=
1777-
options1.ProjectFileName= options2.ProjectFileName
1777+
static memberUseSameProject(options1,options2)=
1778+
match options1.ProjectId, options2.ProjectIdwith
1779+
| Some(projectId1), Some(projectId2)whennot(String.IsNullOrWhiteSpace(projectId1))&&not(String.IsNullOrWhiteSpace(projectId2))->
1780+
String.Equals(projectId1, projectId2, StringComparison.OrdinalIgnoreCase)
1781+
| Some(_), Some(_)
1782+
| None, None-> options1.ProjectFileName= options2.ProjectFileName
1783+
|_->false
17781784

17791785
/// Compare two options sets with respect to the parts of the options that are important to building.
17801786
static memberAreSameForChecking(options1,options2)=
17811787
match options1.Stamp, options2.Stampwith
17821788
| Some x, Some y->(x= y)
17831789
|_->
1784-
options1.ProjectFileName=options2.ProjectFileName&&
1790+
FSharpProjectOptions.UseSameProject(options1,options2)&&
17851791
options1.SourceFiles= options2.SourceFiles&&
17861792
options1.OtherOptions= options2.OtherOptions&&
17871793
options1.UnresolvedReferences= options2.UnresolvedReferences&&
@@ -2155,7 +2161,7 @@ module Helpers =
21552161
/// Determine whether two (fileName,options) keys should be identical w.r.t. resource usage
21562162
letAreSubsumable2((fileName1:string,o1:FSharpProjectOptions),(fileName2:string,o2:FSharpProjectOptions))=
21572163
(fileName1= fileName2)
2158-
&& FSharpProjectOptions.UseSameProjectFileName(o1,o2)
2164+
&& FSharpProjectOptions.UseSameProject(o1,o2)
21592165

21602166
/// Determine whether two (fileName,sourceText,options) keys should be identical w.r.t. parsing
21612167
letAreSameForParsing((fileName1:string,source1:string,options1),(fileName2,source2,options2))=
@@ -2173,7 +2179,7 @@ module Helpers =
21732179
/// Determine whether two (fileName,sourceText,options) keys should be identical w.r.t. resource usage
21742180
letAreSubsumable3((fileName1:string,_,o1:FSharpProjectOptions),(fileName2:string,_,o2:FSharpProjectOptions))=
21752181
(fileName1= fileName2)
2176-
&& FSharpProjectOptions.UseSameProjectFileName(o1,o2)
2182+
&& FSharpProjectOptions.UseSameProject(o1,o2)
21772183

21782184
moduleCompileHelpers=
21792185
letmkCompilationErorHandlers()=
@@ -2316,7 +2322,7 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
23162322
letscriptClosureCache=
23172323
MruCache<ScriptClosureCacheToken, FSharpProjectOptions, LoadClosure>(projectCacheSize,
23182324
areSame=FSharpProjectOptions.AreSameForChecking,
2319-
areSimilar=FSharpProjectOptions.UseSameProjectFileName)
2325+
areSimilar=FSharpProjectOptions.UseSameProject)
23202326

23212327
letscriptClosureCacheLock= Lock<ScriptClosureCacheToken>()
23222328
letframeworkTcImportsCache= FrameworkImportsCache(frameworkTcImportsCacheStrongSize)
@@ -2389,7 +2395,7 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
23892395
MruCache<CompilationThreadToken, FSharpProjectOptions,(IncrementalBuilder option* FSharpErrorInfo[]* IDisposable)>
23902396
(keepStrongly=projectCacheSize, keepMax=projectCacheSize,
23912397
areSame= FSharpProjectOptions.AreSameForChecking,
2392-
areSimilar= FSharpProjectOptions.UseSameProjectFileName,
2398+
areSimilar= FSharpProjectOptions.UseSameProject,
23932399
requiredToKeep=(fun(builderOpt,_,_)->match builderOptwith None->false| Some(b:IncrementalBuilder)-> b.IsBeingKeptAliveApartFromCacheEntry),
23942400
onDiscard=(fun(_,_,decrement:IDisposable)-> decrement.Dispose()))
23952401

@@ -2660,7 +2666,7 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
26602666
letexecWithReactorAsync action= reactor.EnqueueAndAwaitOpAsync(userOpName,"ParseAndCheckFileInProject", filename, action)
26612667
async{
26622668
try
2663-
letstrGuid="_"+Guid.NewGuid().ToString()
2669+
letstrGuid="_ProjectId="+(options.ProjectId|> Option.defaultValue"null")
26642670
Logger.LogBlockMessageStart(filename+ strGuid) LogCompilerFunctionId.Service_ParseAndCheckFileInProject
26652671

26662672
if implicitlyStartBackgroundWorkthen
@@ -2832,6 +2838,7 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
28322838
letoptions=
28332839
{
28342840
ProjectFileName= filename+".fsproj"// Make a name that is unique in this directory.
2841+
ProjectId= None
28352842
SourceFiles= loadClosure.SourceFiles|> List.map fst|> List.toArray
28362843
OtherOptions= otherFlags
28372844
ReferencedProjects=[||]
@@ -3184,6 +3191,7 @@ type FSharpChecker(legacyReferenceResolver, projectCacheSize, keepAssemblyConten
31843191
memberic.GetProjectOptionsFromCommandLineArgs(projectFileName,argv,?loadedTimeStamp,?extraProjectInfo:obj)=
31853192
letloadedTimeStamp= defaultArg loadedTimeStamp DateTime.MaxValue// Not 'now', we don't want to force reloading
31863193
{ ProjectFileName= projectFileName
3194+
ProjectId= None
31873195
SourceFiles=[||]// the project file names will be inferred from the ProjectOptions
31883196
OtherOptions= argv
31893197
ReferencedProjects=[||]

‎src/fsharp/service/service.fsi‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ type public FSharpProjectOptions =
309309
// Note that this may not reduce to just the project directory, because there may be two projects in the same directory.
310310
ProjectFileName:string
311311

312+
/// This is the unique identifier for the project, uses StringComparison.OrdinalIgnoreCase. If it's None, will key off of ProjectFileName in our caching.
313+
ProjectId:string option
314+
312315
/// The files in the project
313316
SourceFiles:string[]
314317

‎tests/service/AssemblyContentProviderTests.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ let private filePath = "C:\\test.fs"
1717

1818
letprivateprojectOptions:FSharpProjectOptions=
1919
{ ProjectFileName="C:\\test.fsproj"
20+
ProjectId= None
2021
SourceFiles=[| filePath|]
2122
ReferencedProjects=[||]
2223
OtherOptions=[||]

‎tests/service/FileSystemTests.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ let ``FileSystem compilation test``() =
100100
yield"-r:"+ r|]
101101

102102
{ ProjectFileName=@"c:\mycode\compilation.fsproj"// Make a name that is unique in this directory.
103+
ProjectId= None
103104
SourceFiles=[| fileName1; fileName2|]
104105
OtherOptions= allFlags
105106
ReferencedProjects=[||];

‎tests/service/MultiProjectAnalysisTests.fs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ let ``Type provider project references should not throw exceptions`` () =
846846
//let options = ProjectCracker.GetProjectOptionsFromProjectFile(projectFile, [("Configuration", "Debug")])
847847
letoptions=
848848
{ProjectFileName=__SOURCE_DIRECTORY__+@"/data/TypeProviderConsole/TypeProviderConsole.fsproj";
849+
ProjectId= None
849850
SourceFiles=[|__SOURCE_DIRECTORY__+@"/data/TypeProviderConsole/Program.fs"|];
850851
Stamp= None
851852
OtherOptions=
@@ -871,6 +872,7 @@ let ``Type provider project references should not throw exceptions`` () =
871872
ReferencedProjects=
872873
[|(__SOURCE_DIRECTORY__+@"/data/TypeProviderLibrary/TypeProviderLibrary.dll",
873874
{ProjectFileName=__SOURCE_DIRECTORY__+@"/data/TypeProviderLibrary/TypeProviderLibrary.fsproj";
875+
ProjectId= None
874876
SourceFiles=[|__SOURCE_DIRECTORY__+@"/data/TypeProviderLibrary/Library1.fs"|];
875877
Stamp= None
876878
OtherOptions=
@@ -935,6 +937,7 @@ let ``Projects creating generated types should not utilize cross-project-referen
935937
letoptions=
936938
{ProjectFileName=
937939
__SOURCE_DIRECTORY__+@"/data/TypeProvidersBug/TestConsole/TestConsole.fsproj";
940+
ProjectId= None
938941
SourceFiles=
939942
[|__SOURCE_DIRECTORY__+@"/data/TypeProvidersBug/TestConsole/AssemblyInfo.fs";
940943
__SOURCE_DIRECTORY__+@"/data/TypeProvidersBug/TestConsole/Program.fs"|];
@@ -963,6 +966,7 @@ let ``Projects creating generated types should not utilize cross-project-referen
963966
[|(__SOURCE_DIRECTORY__+@"/data/TypeProvidersBug/TypeProvidersBug/bin/Debug/TypeProvidersBug.dll",
964967
{ProjectFileName=
965968
__SOURCE_DIRECTORY__+@"/data/TypeProvidersBug/TypeProvidersBug/TypeProvidersBug.fsproj";
969+
ProjectId= None
966970
SourceFiles=
967971
[|__SOURCE_DIRECTORY__+@"/data/TypeProvidersBug/TypeProvidersBug/AssemblyInfo.fs";
968972
__SOURCE_DIRECTORY__+@"/data/TypeProvidersBug/TypeProvidersBug/Library1.fs"|];

‎vsintegration/Utils/LanguageServiceProfiling/Options.fs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ let FCS (repositoryDir: string) : Options =
196196

197197
{ Options=
198198
{ProjectFileName= repositoryDir</>@"src\fsharp\FSharp.Compiler.Private\FSharp.Compiler.Private.fsproj"
199+
ProjectId= None
199200
SourceFiles= files|> Array.map(fun x-> repositoryDir</> x)
200201
OtherOptions=
201202
[|@"-o:obj\Release\FSharp.Compiler.Private.dll";"-g";"--noframework";
@@ -301,6 +302,7 @@ let FCS (repositoryDir: string) : Options =
301302
letVFPT(repositoryDir:string):Options=
302303
{ Options=
303304
{ProjectFileName= repositoryDir</>@"src\FSharp.Editing\FSharp.Editing.fsproj"
305+
ProjectId= None
304306
SourceFiles=
305307
[|@"src\FSharp.Editing\AssemblyInfo.fs";
306308
@"src\FSharp.Editing\Common\Utils.fs";

‎vsintegration/src/FSharp.Editor/Common/Extensions.fs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ type System.IServiceProvider with
2424
memberx.GetService<'T>()= x.GetService(typeof<'T>):?> 'T
2525
memberx.GetService<'S,'T>()= x.GetService(typeof<'S>):?> 'T
2626

27-
2827
typeFSharpNavigationDeclarationItemwith
2928
memberx.RoslynGlyph:Glyph=
3029
match x.Glyphwith

‎vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ type internal FSharpProjectOptionsManager
172172

173173
/// Update the info for a project in the project table
174174
memberthis.UpdateProjectInfo(tryGetOrCreateProjectId,projectId,site,userOpName,invalidateConfig)=
175-
Logger.LogMessage("InvalidateConfig="+ invalidateConfig.ToString()) LogEditorFunctionId.LanguageService_UpdateProjectInfo
175+
Logger.Log LogEditorFunctionId.LanguageService_UpdateProjectInfo
176176
projectOptionsTable.AddOrUpdateProject(projectId,(fun isRefresh->
177177
letextraProjectInfo= Some(box workspace)
178178
lettryGetOptionsForReferencedProject f= f|> tryGetOrCreateProjectId|> Option.bind this.TryGetOptionsForProject|> Option.map(fun(_,_,projectOptions)-> projectOptions)
179-
letreferencedProjects,projectOptions= ProjectSitesAndFiles.GetProjectOptionsForProjectSite(Settings.LanguageServicePerformance.EnableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, site, serviceProvider,(tryGetOrCreateProjectId(site.ProjectFileName)), site.ProjectFileName, extraProjectInfo, Some projectOptionsTable)
179+
letreferencedProjects,projectOptions= ProjectSitesAndFiles.GetProjectOptionsForProjectSite(Settings.LanguageServicePerformance.EnableInMemoryCrossProjectReferences, tryGetOptionsForReferencedProject, site, serviceProvider,Some(projectId), site.ProjectFileName, extraProjectInfo, Some projectOptionsTable)
180180
if invalidateConfigthen checkerProvider.Checker.InvalidateConfiguration(projectOptions, startBackgroundCompileIfAlreadySeen=not isRefresh, userOpName= userOpName+".UpdateProjectInfo")
181181
letreferencedProjectIds= referencedProjects|> Array.choose tryGetOrCreateProjectId
182182
letparsingOptions,_= checkerProvider.Checker.GetParsingOptionsFromProjectOptions(projectOptions)
@@ -427,6 +427,7 @@ type internal FSharpLanguageService(package : FSharpPackage) =
427427

428428
memberprivatethis.OnProjectAdded(projectId:ProjectId)= projectInfoManager.UpdateProjectInfoWithProjectId(projectId,"OnProjectAdded", invalidateConfig=true)
429429
memberprivatethis.OnProjectReloaded(projectId:ProjectId)= projectInfoManager.UpdateProjectInfoWithProjectId(projectId,"OnProjectReloaded", invalidateConfig=true)
430+
memberprivatethis.OnProjectRemoved(projectId)= projectInfoManager.ClearInfoForProject(projectId)
430431
memberprivatethis.OnDocumentAdded(projectId:ProjectId,documentId:DocumentId)= projectInfoManager.UpdateDocumentInfoWithProjectId(projectId, documentId,"OnDocumentAdded", invalidateConfig=true)
431432
memberprivatethis.OnDocumentReloaded(projectId:ProjectId,documentId:DocumentId)= projectInfoManager.UpdateDocumentInfoWithProjectId(projectId, documentId,"OnDocumentReloaded", invalidateConfig=true)
432433

@@ -438,10 +439,10 @@ type internal FSharpLanguageService(package : FSharpPackage) =
438439
match args.Kindwith
439440
| WorkspaceChangeKind.ProjectAdded-> this.OnProjectAdded(args.ProjectId)
440441
| WorkspaceChangeKind.ProjectReloaded-> this.OnProjectReloaded(args.ProjectId)
442+
| WorkspaceChangeKind.ProjectRemoved-> this.OnProjectRemoved(args.ProjectId)
441443
| WorkspaceChangeKind.DocumentAdded-> this.OnDocumentAdded(args.ProjectId, args.DocumentId)
442444
| WorkspaceChangeKind.DocumentReloaded-> this.OnDocumentReloaded(args.ProjectId, args.DocumentId)
443445
| WorkspaceChangeKind.DocumentRemoved
444-
| WorkspaceChangeKind.ProjectRemoved
445446
| WorkspaceChangeKind.AdditionalDocumentAdded
446447
| WorkspaceChangeKind.AdditionalDocumentReloaded
447448
| WorkspaceChangeKind.AdditionalDocumentRemoved
@@ -694,4 +695,4 @@ type internal FSharpLanguageService(package : FSharpPackage) =
694695
this.SetupStandAloneFile(filename, fileContents, this.Workspace, hier)
695696

696697
|_->()
697-
|_->()
698+
|_->()

‎vsintegration/src/FSharp.Editor/LanguageService/ProjectSitesAndFiles.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ type internal ProjectSitesAndFiles() =
274274
letoption=
275275
letnewOption()={
276276
ProjectFileName= projectSite.ProjectFileName
277+
ProjectId= projectId|> Option.map(fun x-> x.Id.ToString())
277278
SourceFiles= projectSite.CompilationSourceFiles
278279
OtherOptions= projectSite.CompilationOptions
279280
ReferencedProjects= referencedProjectOptions

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp