diff --git a/src/Workspaces/Core/Portable/PublicAPI.Unshipped.txt b/src/Workspaces/Core/Portable/PublicAPI.Unshipped.txt index 5a3f939de6a22914540b8b007f35eea0423511fe..99b0a556faea430651c24597e2f6fdcabb213854 100644 --- a/src/Workspaces/Core/Portable/PublicAPI.Unshipped.txt +++ b/src/Workspaces/Core/Portable/PublicAPI.Unshipped.txt @@ -10,6 +10,7 @@ Microsoft.CodeAnalysis.Solution.AddAnalyzerConfigDocuments(System.Collections.Im Microsoft.CodeAnalysis.Solution.ContainsAnalyzerConfigDocument(Microsoft.CodeAnalysis.DocumentId documentId) -> bool Microsoft.CodeAnalysis.Solution.GetAnalyzerConfigDocument(Microsoft.CodeAnalysis.DocumentId documentId) -> Microsoft.CodeAnalysis.AnalyzerConfigDocument Microsoft.CodeAnalysis.Solution.RemoveAnalyzerConfigDocument(Microsoft.CodeAnalysis.DocumentId documentId) -> Microsoft.CodeAnalysis.Solution +Microsoft.CodeAnalysis.Solution.WithAnalyzerConfigDocumentText(Microsoft.CodeAnalysis.DocumentId documentId, Microsoft.CodeAnalysis.Text.SourceText text, Microsoft.CodeAnalysis.PreservationMode mode = Microsoft.CodeAnalysis.PreservationMode.PreserveValue) -> Microsoft.CodeAnalysis.Solution Microsoft.CodeAnalysis.Solution.WithAnalyzerConfigDocumentTextLoader(Microsoft.CodeAnalysis.DocumentId documentId, Microsoft.CodeAnalysis.TextLoader loader, Microsoft.CodeAnalysis.PreservationMode mode) -> Microsoft.CodeAnalysis.Solution Microsoft.CodeAnalysis.Workspace.CheckAnalyzerConfigDocumentIsInCurrentSolution(Microsoft.CodeAnalysis.DocumentId documentId) -> void Microsoft.CodeAnalysis.Workspace.CheckAnalyzerConfigDocumentIsNotInCurrentSolution(Microsoft.CodeAnalysis.DocumentId documentId) -> void diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/AnalyzerConfigDocumentState.cs b/src/Workspaces/Core/Portable/Workspace/Solution/AnalyzerConfigDocumentState.cs index 4eb52315b32cd3f17f726ad1d8c7f1042484d94b..74792a0ad438930c4bce1275411df7f10231a68c 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/AnalyzerConfigDocumentState.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/AnalyzerConfigDocumentState.cs @@ -48,6 +48,11 @@ public new AnalyzerConfigDocumentState UpdateText(TextLoader loader, Preservatio return (AnalyzerConfigDocumentState)base.UpdateText(loader, mode); } + public new AnalyzerConfigDocumentState UpdateText(SourceText text, PreservationMode mode) + { + return (AnalyzerConfigDocumentState)base.UpdateText(text, mode); + } + protected override TextDocumentState UpdateText(ValueSource newTextSource, PreservationMode mode, bool incremental) { return new AnalyzerConfigDocumentState( diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs b/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs index 363ce67110354694200e569c1b37c328b91e1452..552f789bcbc427f05faea8a4b5bd2f900b5aa42c 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs @@ -1024,6 +1024,21 @@ public Solution WithAdditionalDocumentTextLoader(DocumentId documentId, TextLoad return new Solution(newState); } + /// + /// Creates a new solution instance with the analyzer config document specified updated to have the text + /// supplied by the text loader. + /// + public Solution WithAnalyzerConfigDocumentText(DocumentId documentId, SourceText text, PreservationMode mode = PreservationMode.PreserveValue) + { + var newState = _state.WithAnalyzerConfigDocumentText(documentId, text, mode); + if (newState == _state) + { + return this; + } + + return new Solution(newState); + } + /// /// Creates a new solution instance with the analyzer config document specified updated to have the text /// supplied by the text loader. diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.cs b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.cs index 42d9fc293f133ae4b356a2b42773c7f4d220f929..d288946cd1822000a919fc5d88389eb5ef9d1ecf 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.cs @@ -1380,6 +1380,33 @@ public SolutionState WithAdditionalDocumentText(DocumentId documentId, SourceTex return newSolution; } + /// + /// Creates a new solution instance with the document specified updated to have the text + /// specified. + /// + public SolutionState WithAnalyzerConfigDocumentText(DocumentId documentId, SourceText text, PreservationMode mode = PreservationMode.PreserveValue) + { + if (documentId == null) + { + throw new ArgumentNullException(nameof(documentId)); + } + + if (text == null) + { + throw new ArgumentNullException(nameof(text)); + } + + CheckContainsAnalyzerConfigDocument(documentId); + + var oldDocument = this.GetAnalyzerConfigDocumentState(documentId); + if (oldDocument.TryGetText(out var oldText) && text == oldText) + { + return this; + } + + return this.WithAnalyzerConfigDocumentState(oldDocument.UpdateText(text, mode), textChanged: true); + } + /// /// Creates a new solution instance with the document specified updated to have the text /// and version specified.