From df1b39b404f53268b3d760e9ff7de4535cb20ae7 Mon Sep 17 00:00:00 2001 From: vweijsters Date: Fri, 30 Oct 2015 17:31:41 +0100 Subject: [PATCH] Disabled SA1649 code fix for linked files --- .../DocumentationRules/SA1649CodeFixProvider.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1649CodeFixProvider.cs b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1649CodeFixProvider.cs index 51e7391f7..c570ec926 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1649CodeFixProvider.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1649CodeFixProvider.cs @@ -34,6 +34,13 @@ public override FixAllProvider GetFixAllProvider() /// public override Task RegisterCodeFixesAsync(CodeFixContext context) { + // Do not offer a codefix when there are linked documents. + // Roslyn will currently not handle this properly, creating a copy of the file, instead of a link. + if (context.Document.GetLinkedDocumentIds().Length > 0) + { + return SpecializedTasks.CompletedTask; + } + foreach (var diagnostic in context.Diagnostics) { context.RegisterCodeFix( @@ -61,12 +68,18 @@ private static async Task GetTransformedSolutionAsync(Document documen .RemoveDocument(document.Id) .AddDocument(newDocumentId, expectedFileName, syntaxRoot, document.Folders, newPath); + /* For future usage: // Make sure to also add the file to linked projects foreach (var linkedDocumentId in document.GetLinkedDocumentIds()) { - DocumentId linkedExtractedDocumentId = DocumentId.CreateNewId(linkedDocumentId.ProjectId); - newSolution = newSolution.AddDocument(linkedExtractedDocumentId, expectedFileName, syntaxRoot, document.Folders); + var linkedDocument = solution.GetDocument(linkedDocumentId); + + DocumentId newLinkedDocumentId = DocumentId.CreateNewId(linkedDocumentId.ProjectId); + newSolution = newSolution + .RemoveDocument(linkedDocumentId) + .AddDocument(newLinkedDocumentId, expectedFileName, syntaxRoot, linkedDocument.Folders, newPath); } + */ return newSolution; }