|
14 | 14 | using Microsoft.CodeAnalysis.AddImport; |
15 | 15 | using Microsoft.CodeAnalysis.CodeCleanup; |
16 | 16 | using Microsoft.CodeAnalysis.CodeGeneration; |
| 17 | +using Microsoft.CodeAnalysis.CodeRefactorings.SyncNamespace; |
17 | 18 | using Microsoft.CodeAnalysis.Editing; |
| 19 | +using Microsoft.CodeAnalysis.ErrorReporting; |
18 | 20 | using Microsoft.CodeAnalysis.FindSymbols; |
19 | 21 | using Microsoft.CodeAnalysis.Formatting; |
20 | 22 | using Microsoft.CodeAnalysis.Host; |
@@ -470,7 +472,20 @@ private static SyntaxNode CreateImport(SyntaxGenerator syntaxGenerator, string n |
470 | 472 | .ConfigureAwait(false); |
471 | 473 | var solutionWithChangedNamespace = documentWithNewNamespace.Project.Solution; |
472 | 474 |
|
473 | | - var refLocationGroups = refLocationsInOtherDocuments.GroupBy(loc => loc.Document.Id); |
| 475 | + var refLocationsInSolution = refLocationsInOtherDocuments |
| 476 | + .Where(loc => solutionWithChangedNamespace.ContainsDocument(loc.Document.Id)) |
| 477 | + .ToImmutableArray(); |
| 478 | + |
| 479 | + if (refLocationsInSolution.Length != refLocationsInOtherDocuments.Count) |
| 480 | + { |
| 481 | + // We have received feedback indicate some documents are not in the solution. |
| 482 | + // Report this as non-fatal error if this happens. |
| 483 | + FatalError.ReportNonFatalError( |
| 484 | + new SyncNamespaceDocumentsNotInSolutionException(refLocationsInOtherDocuments |
| 485 | + .Where(loc => !solutionWithChangedNamespace.ContainsDocument(loc.Document.Id)).Distinct().SelectAsArray(loc => loc.Document.Id))); |
| 486 | + } |
| 487 | + |
| 488 | + var refLocationGroups = refLocationsInSolution.GroupBy(loc => loc.Document.Id); |
474 | 489 |
|
475 | 490 | var fixedDocuments = await Task.WhenAll( |
476 | 491 | refLocationGroups.Select(refInOneDocument => |
|
0 commit comments