Skip to content
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

Disabled SA1649 code fix for linked files #1714

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public override FixAllProvider GetFixAllProvider()
/// <inheritdoc/>
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(
Expand Down Expand Up @@ -61,12 +68,18 @@ private static async Task<Solution> 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;
}
Expand Down