-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Provide solution methods to allow updating a bulk set of documents at once. #73394
Merged
CyrusNajmabadi
merged 9 commits into
dotnet:main
from
CyrusNajmabadi:updateDocumentsAtOnce
May 8, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
763fcb1
In progress
CyrusNajmabadi a39098d
Merge branch 'main' into updateDocumentsAtOnce
CyrusNajmabadi 77c88b3
update roots in parallel
CyrusNajmabadi e2cf63f
Use new helper
CyrusNajmabadi 3e2eceb
Use new helper
CyrusNajmabadi e2cf7c7
Update source texts as well
CyrusNajmabadi 90c3529
Simplify
CyrusNajmabadi b124c65
Simplify
CyrusNajmabadi 8d017b9
Simplify
CyrusNajmabadi 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
This file contains 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 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 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 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 |
---|---|---|
|
@@ -185,28 +185,35 @@ private static async Task<VersionStamp> ComputeLatestDocumentVersionAsync(TextDo | |
} | ||
|
||
private AsyncLazy<VersionStamp> CreateLazyLatestDocumentTopLevelChangeVersion( | ||
TextDocumentState newDocument, | ||
ImmutableArray<TextDocumentState> newDocuments, | ||
TextDocumentStates<DocumentState> newDocumentStates, | ||
TextDocumentStates<AdditionalDocumentState> newAdditionalDocumentStates) | ||
{ | ||
if (_lazyLatestDocumentTopLevelChangeVersion.TryGetValue(out var oldVersion)) | ||
{ | ||
return AsyncLazy.Create(static (arg, c) => | ||
ComputeTopLevelChangeTextVersionAsync(arg.oldVersion, arg.newDocument, c), | ||
arg: (oldVersion, newDocument)); | ||
return AsyncLazy.Create(static (arg, cancellationToken) => | ||
ComputeTopLevelChangeTextVersionAsync(arg.oldVersion, arg.newDocuments, cancellationToken), | ||
arg: (oldVersion, newDocuments)); | ||
} | ||
else | ||
{ | ||
return AsyncLazy.Create(static (arg, c) => | ||
ComputeLatestDocumentTopLevelChangeVersionAsync(arg.newDocumentStates, arg.newAdditionalDocumentStates, c), | ||
return AsyncLazy.Create(static (arg, cancellationToken) => | ||
ComputeLatestDocumentTopLevelChangeVersionAsync(arg.newDocumentStates, arg.newAdditionalDocumentStates, cancellationToken), | ||
arg: (newDocumentStates, newAdditionalDocumentStates)); | ||
} | ||
} | ||
|
||
private static async Task<VersionStamp> ComputeTopLevelChangeTextVersionAsync(VersionStamp oldVersion, TextDocumentState newDocument, CancellationToken cancellationToken) | ||
private static async Task<VersionStamp> ComputeTopLevelChangeTextVersionAsync( | ||
VersionStamp oldVersion, ImmutableArray<TextDocumentState> newDocuments, CancellationToken cancellationToken) | ||
{ | ||
var newVersion = await newDocument.GetTopLevelChangeTextVersionAsync(cancellationToken).ConfigureAwait(false); | ||
return newVersion.GetNewerVersion(oldVersion); | ||
var finalVersion = oldVersion; | ||
foreach (var newDocument in newDocuments) | ||
{ | ||
var newVersion = await newDocument.GetTopLevelChangeTextVersionAsync(cancellationToken).ConfigureAwait(false); | ||
finalVersion = newVersion.GetNewerVersion(finalVersion); | ||
} | ||
|
||
return finalVersion; | ||
} | ||
|
||
private static async Task<VersionStamp> ComputeLatestDocumentTopLevelChangeVersionAsync(TextDocumentStates<DocumentState> documentStates, TextDocumentStates<AdditionalDocumentState> additionalDocumentStates, CancellationToken cancellationToken) | ||
|
@@ -834,16 +841,25 @@ public ProjectState RemoveAllNormalDocuments() | |
} | ||
|
||
public ProjectState UpdateDocument(DocumentState newDocument, bool contentChanged) | ||
=> UpdateDocuments([newDocument], contentChanged); | ||
|
||
public ProjectState UpdateDocuments(ImmutableArray<DocumentState> newDocuments, bool contentChanged) | ||
{ | ||
var oldDocument = DocumentStates.GetRequiredState(newDocument.Id); | ||
if (oldDocument == newDocument) | ||
{ | ||
var oldDocuments = newDocuments.SelectAsArray(d => DocumentStates.GetRequiredState(d.Id)); | ||
if (oldDocuments.SequenceEqual(newDocuments)) | ||
return this; | ||
} | ||
|
||
var newDocumentStates = DocumentStates.SetState(newDocument.Id, newDocument); | ||
// Must not be empty as we would have otherwise bailed out in the check above. | ||
Contract.ThrowIfTrue(newDocuments.IsEmpty); | ||
|
||
var newDocumentStates = DocumentStates.SetStates(newDocuments); | ||
|
||
// When computing the latest dependent version, we just need to know how | ||
GetLatestDependentVersions( | ||
newDocumentStates, AdditionalDocumentStates, oldDocument, newDocument, contentChanged, | ||
newDocumentStates, AdditionalDocumentStates, | ||
oldDocuments.CastArray<TextDocumentState>(), | ||
newDocuments.CastArray<TextDocumentState>(), | ||
contentChanged, | ||
out var dependentDocumentVersion, out var dependentSemanticVersion); | ||
|
||
return With( | ||
|
@@ -860,9 +876,9 @@ public ProjectState UpdateAdditionalDocument(AdditionalDocumentState newDocument | |
return this; | ||
} | ||
|
||
var newDocumentStates = AdditionalDocumentStates.SetState(newDocument.Id, newDocument); | ||
var newDocumentStates = AdditionalDocumentStates.SetState(newDocument); | ||
GetLatestDependentVersions( | ||
DocumentStates, newDocumentStates, oldDocument, newDocument, contentChanged, | ||
DocumentStates, newDocumentStates, [oldDocument], [newDocument], contentChanged, | ||
out var dependentDocumentVersion, out var dependentSemanticVersion); | ||
|
||
return this.With( | ||
|
@@ -879,7 +895,7 @@ public ProjectState UpdateAnalyzerConfigDocument(AnalyzerConfigDocumentState new | |
return this; | ||
} | ||
|
||
var newDocumentStates = AnalyzerConfigDocumentStates.SetState(newDocument.Id, newDocument); | ||
var newDocumentStates = AnalyzerConfigDocumentStates.SetState(newDocument); | ||
|
||
return CreateNewStateForChangedAnalyzerConfigDocuments(newDocumentStates); | ||
} | ||
|
@@ -899,46 +915,71 @@ public ProjectState UpdateDocumentsOrder(ImmutableList<DocumentId> documentIds) | |
private void GetLatestDependentVersions( | ||
TextDocumentStates<DocumentState> newDocumentStates, | ||
TextDocumentStates<AdditionalDocumentState> newAdditionalDocumentStates, | ||
TextDocumentState oldDocument, TextDocumentState newDocument, | ||
ImmutableArray<TextDocumentState> oldDocuments, | ||
ImmutableArray<TextDocumentState> newDocuments, | ||
bool contentChanged, | ||
out AsyncLazy<VersionStamp> dependentDocumentVersion, out AsyncLazy<VersionStamp> dependentSemanticVersion) | ||
out AsyncLazy<VersionStamp> dependentDocumentVersion, | ||
out AsyncLazy<VersionStamp> dependentSemanticVersion) | ||
{ | ||
var recalculateDocumentVersion = false; | ||
var recalculateSemanticVersion = false; | ||
|
||
if (contentChanged) | ||
{ | ||
if (oldDocument.TryGetTextVersion(out var oldVersion)) | ||
foreach (var oldDocument in oldDocuments) | ||
{ | ||
if (!_lazyLatestDocumentVersion.TryGetValue(out var documentVersion) || documentVersion == oldVersion) | ||
if (oldDocument.TryGetTextVersion(out var oldVersion)) | ||
{ | ||
recalculateDocumentVersion = true; | ||
} | ||
if (!_lazyLatestDocumentVersion.TryGetValue(out var documentVersion) || documentVersion == oldVersion) | ||
recalculateDocumentVersion = true; | ||
|
||
if (!_lazyLatestDocumentTopLevelChangeVersion.TryGetValue(out var semanticVersion) || semanticVersion == oldVersion) | ||
{ | ||
recalculateSemanticVersion = true; | ||
if (!_lazyLatestDocumentTopLevelChangeVersion.TryGetValue(out var semanticVersion) || semanticVersion == oldVersion) | ||
recalculateSemanticVersion = true; | ||
} | ||
|
||
if (recalculateDocumentVersion && recalculateSemanticVersion) | ||
break; | ||
} | ||
} | ||
|
||
dependentDocumentVersion = recalculateDocumentVersion | ||
? AsyncLazy.Create(static (arg, c) => | ||
ComputeLatestDocumentVersionAsync(arg.newDocumentStates, arg.newAdditionalDocumentStates, c), | ||
arg: (newDocumentStates, newAdditionalDocumentStates)) | ||
: contentChanged | ||
? AsyncLazy.Create(static (newDocument, c) => | ||
newDocument.GetTextVersionAsync(c), | ||
arg: newDocument) | ||
: _lazyLatestDocumentVersion; | ||
|
||
dependentSemanticVersion = recalculateSemanticVersion | ||
? AsyncLazy.Create(static (arg, c) => | ||
ComputeLatestDocumentTopLevelChangeVersionAsync(arg.newDocumentStates, arg.newAdditionalDocumentStates, c), | ||
arg: (newDocumentStates, newAdditionalDocumentStates)) | ||
: contentChanged | ||
? CreateLazyLatestDocumentTopLevelChangeVersion(newDocument, newDocumentStates, newAdditionalDocumentStates) | ||
: _lazyLatestDocumentTopLevelChangeVersion; | ||
if (recalculateDocumentVersion) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i broke the nested conditionals into if-statements as it was breaking my brain. |
||
{ | ||
dependentDocumentVersion = AsyncLazy.Create(static (arg, cancellationToken) => | ||
ComputeLatestDocumentVersionAsync(arg.newDocumentStates, arg.newAdditionalDocumentStates, cancellationToken), | ||
arg: (newDocumentStates, newAdditionalDocumentStates)); | ||
} | ||
else if (contentChanged) | ||
{ | ||
dependentDocumentVersion = AsyncLazy.Create( | ||
static async (newDocuments, cancellationToken) => | ||
{ | ||
var finalVersion = await newDocuments[0].GetTextVersionAsync(cancellationToken).ConfigureAwait(false); | ||
for (var i = 1; i < newDocuments.Length; i++) | ||
finalVersion = finalVersion.GetNewerVersion(await newDocuments[i].GetTextVersionAsync(cancellationToken).ConfigureAwait(false)); | ||
|
||
return finalVersion; | ||
}, | ||
arg: newDocuments); | ||
} | ||
else | ||
{ | ||
dependentDocumentVersion = _lazyLatestDocumentVersion; | ||
} | ||
|
||
if (recalculateSemanticVersion) | ||
{ | ||
dependentSemanticVersion = AsyncLazy.Create(static (arg, cancellationToken) => | ||
ComputeLatestDocumentTopLevelChangeVersionAsync(arg.newDocumentStates, arg.newAdditionalDocumentStates, cancellationToken), | ||
arg: (newDocumentStates, newAdditionalDocumentStates)); | ||
} | ||
else if (contentChanged) | ||
{ | ||
dependentSemanticVersion = CreateLazyLatestDocumentTopLevelChangeVersion(newDocuments, newDocumentStates, newAdditionalDocumentStates); | ||
} | ||
else | ||
{ | ||
dependentSemanticVersion = _lazyLatestDocumentTopLevelChangeVersion; | ||
} | ||
} | ||
|
||
public void AddDocumentIdsWithFilePath(ref TemporaryArray<DocumentId> temporaryArray, string filePath) | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
view with whitespace off.