Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,11 +1391,15 @@ internal Solution WithDocumentSyntaxRoots(ImmutableArray<(DocumentId documentId,
return WithCompilationState(CompilationState.WithDocumentSyntaxRoots(syntaxRoots, mode));
}

internal Solution WithDocumentContentsFrom(DocumentId documentId, DocumentState documentState, bool forceEvenIfTreesWouldDiffer)
=> WithCompilationState(CompilationState.WithDocumentContentsFrom([(documentId, documentState)], forceEvenIfTreesWouldDiffer));

internal Solution WithDocumentContentsFrom(ImmutableArray<(DocumentId documentId, DocumentState documentState)> documentIdsAndStates, bool forceEvenIfTreesWouldDiffer)
=> WithCompilationState(CompilationState.WithDocumentContentsFrom(documentIdsAndStates, forceEvenIfTreesWouldDiffer));
internal Solution WithDocumentContentsFrom(DocumentId documentId, DocumentState documentState)
=> WithDocumentContentsFrom([(documentId, documentState)]);

internal Solution WithDocumentContentsFrom(ImmutableArray<(DocumentId documentId, DocumentState documentState)> documentIdsAndStates)
// This code path is all about updating linked files to match the contents of the document they are linked to.
// We always want to try to allow the linked files to reuse the root from the linked document if possible, or
// reparse if it is not. Hence why we pass `forceEvenIfTreesWouldDiffer: false` as we don't want reuse in the
// cases like when PP directives change and the docs contain a #if directive.
=> WithCompilationState(CompilationState.WithDocumentContentsFrom(documentIdsAndStates, forceEvenIfTreesWouldDiffer: false));

/// <summary>
/// Creates a new solution instance with the document specified updated to have the source
Expand Down
6 changes: 3 additions & 3 deletions src/Workspaces/Core/Portable/Workspace/Workspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ static Solution UpdateAddedDocumentToExistingContentsInSolution(
if (relatedDocumentIdsAndStates.IsEmpty)
return solution;

return solution.WithDocumentContentsFrom(relatedDocumentIdsAndStates.ToImmutableAndClear(), forceEvenIfTreesWouldDiffer: false);
return solution.WithDocumentContentsFrom(relatedDocumentIdsAndStates.ToImmutableAndClear());
}

static Solution UpdateExistingDocumentsToChangedDocumentContents(Solution solution, HashSet<DocumentId> changedDocumentIds)
Expand Down Expand Up @@ -394,7 +394,7 @@ static Solution UpdateExistingDocumentsToChangedDocumentContents(Solution soluti

var relatedDocumentIdsAndStatesArray = relatedDocumentIdsAndStates.SelectAsArray(static kvp => (kvp.Key, kvp.Value));

return solution.WithDocumentContentsFrom(relatedDocumentIdsAndStatesArray, forceEvenIfTreesWouldDiffer: false);
return solution.WithDocumentContentsFrom(relatedDocumentIdsAndStatesArray);
}
}

Expand Down Expand Up @@ -1307,7 +1307,7 @@ private void OnAnyDocumentTextChanged<TArg>(
foreach (var linkedDocumentId in linkedDocumentIds)
{
previousSolution = newSolution;
newSolution = newSolution.WithDocumentContentsFrom(linkedDocumentId, newDocument.DocumentState, forceEvenIfTreesWouldDiffer: false);
newSolution = newSolution.WithDocumentContentsFrom(linkedDocumentId, newDocument.DocumentState);

if (previousSolution != newSolution)
updatedDocumentIds.Add(linkedDocumentId);
Expand Down
Loading