|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
4 |
| -using System; |
5 |
| -using System.Collections.Generic; |
| 4 | +using System.Collections.Immutable; |
6 | 5 | using System.Diagnostics;
|
7 |
| -using System.Linq; |
8 |
| -using System.Text; |
9 |
| -using System.Threading.Tasks; |
10 | 6 | using Microsoft.CodeAnalysis;
|
11 |
| -using Microsoft.CodeAnalysis.Host; |
| 7 | +using Microsoft.CodeAnalysis.ExternalAccess.Watch.Api; |
12 | 8 | using Microsoft.CodeAnalysis.Host.Mef;
|
13 | 9 | using Microsoft.CodeAnalysis.MSBuild;
|
14 |
| -using Microsoft.Extensions.Tools.Internal; |
15 |
| -using Microsoft.CodeAnalysis.ExternalAccess.Watch.Api; |
16 |
| -using System.Collections.Immutable; |
17 | 10 | using Microsoft.CodeAnalysis.Text;
|
| 11 | +using Microsoft.DotNet.Watcher.Internal; |
| 12 | +using Microsoft.Extensions.Tools.Internal; |
18 | 13 |
|
19 | 14 | namespace Microsoft.DotNet.Watcher.Tools;
|
20 | 15 |
|
@@ -106,13 +101,24 @@ ImmutableArray<DocumentInfo> MapDocuments(ProjectId mappedProjectId, IReadOnlyLi
|
106 | 101 | }).ToImmutableArray();
|
107 | 102 | }
|
108 | 103 |
|
109 |
| - public async ValueTask UpdateFileContentAsync(IEnumerable<FileItem> changedFiles, CancellationToken cancellationToken) |
| 104 | + public async ValueTask UpdateFileContentAsync(IEnumerable<ChangedFile> changedFiles, CancellationToken cancellationToken) |
110 | 105 | {
|
111 | 106 | var updatedSolution = CurrentSolution;
|
112 | 107 |
|
113 |
| - foreach (var changedFile in changedFiles) |
| 108 | + var documentsToRemove = new List<DocumentId>(); |
| 109 | + |
| 110 | + foreach (var (changedFile, change) in changedFiles) |
114 | 111 | {
|
| 112 | + // when a file is added we reevaluate the project: |
| 113 | + Debug.Assert(change != ChangeKind.Add); |
| 114 | + |
115 | 115 | var documentIds = updatedSolution.GetDocumentIdsWithFilePath(changedFile.FilePath);
|
| 116 | + if (change == ChangeKind.Delete) |
| 117 | + { |
| 118 | + documentsToRemove.AddRange(documentIds); |
| 119 | + continue; |
| 120 | + } |
| 121 | + |
116 | 122 | foreach (var documentId in documentIds)
|
117 | 123 | {
|
118 | 124 | var textDocument = updatedSolution.GetDocument(documentId)
|
@@ -140,9 +146,17 @@ public async ValueTask UpdateFileContentAsync(IEnumerable<FileItem> changedFiles
|
140 | 146 | }
|
141 | 147 | }
|
142 | 148 |
|
| 149 | + updatedSolution = RemoveDocuments(updatedSolution, documentsToRemove); |
| 150 | + |
143 | 151 | await ReportSolutionFilesAsync(SetCurrentSolution(updatedSolution), cancellationToken);
|
144 | 152 | }
|
145 | 153 |
|
| 154 | + private static Solution RemoveDocuments(Solution solution, IEnumerable<DocumentId> ids) |
| 155 | + => solution |
| 156 | + .RemoveDocuments(ids.Where(id => solution.GetDocument(id) != null).ToImmutableArray()) |
| 157 | + .RemoveAdditionalDocuments(ids.Where(id => solution.GetAdditionalDocument(id) != null).ToImmutableArray()) |
| 158 | + .RemoveAnalyzerConfigDocuments(ids.Where(id => solution.GetAnalyzerConfigDocument(id) != null).ToImmutableArray()); |
| 159 | + |
146 | 160 | private static async ValueTask<SourceText> GetSourceTextAsync(string filePath, CancellationToken cancellationToken)
|
147 | 161 | {
|
148 | 162 | var zeroLengthRetryPerformed = false;
|
|
0 commit comments