Skip to content

Commit 91f19a0

Browse files
committed
ignore file changes not in workspace
1 parent 06cd3a0 commit 91f19a0

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,8 @@ public async Task<ImmutableArray<ReferencedSymbol>> FindAllSymbolReferences(ISym
920920
return null;
921921
}
922922

923-
public async Task UpdateDocument(SharpIdeFile fileModel, string newContent)
923+
// Returns true if the document was found and updated, otherwise false
924+
public async Task<bool> UpdateDocument(SharpIdeFile fileModel, string newContent)
924925
{
925926
using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(UpdateDocument)}");
926927
await _solutionLoadedTcs.Task;
@@ -937,7 +938,7 @@ public async Task UpdateDocument(SharpIdeFile fileModel, string newContent)
937938
if (documentId is null)
938939
{
939940
_logger.LogWarning("UpdateDocument failed: Document '{DocumentPath}' not found in workspace", fileModel.Path);
940-
return;
941+
return false;
941942
}
942943

943944
var newText = SourceText.From(newContent, Encoding.UTF8);
@@ -957,6 +958,11 @@ public async Task UpdateDocument(SharpIdeFile fileModel, string newContent)
957958
{
958959
_workspace.OnAnalyzerConfigDocumentTextChanged(documentId, newText, PreservationMode.PreserveIdentity);
959960
}
961+
else
962+
{
963+
return false;
964+
}
965+
return true;
960966
}
961967

962968
public async Task AddDocument(SharpIdeFile fileModel, string content)
@@ -1022,7 +1028,7 @@ public async Task AddDocument(SharpIdeFile fileModel, string content)
10221028
}, WorkspaceChangeKind.DocumentAdded, documentId: documentId);
10231029
}
10241030

1025-
public async Task RemoveDocument(SharpIdeFile fileModel)
1031+
public async Task<bool> RemoveDocument(SharpIdeFile fileModel)
10261032
{
10271033
using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(AddDocument)}");
10281034
await _solutionLoadedTcs.Task;
@@ -1038,7 +1044,7 @@ public async Task RemoveDocument(SharpIdeFile fileModel)
10381044
if (documentId is null)
10391045
{
10401046
_logger.LogWarning("RemoveDocument failed: Document '{DocumentPath}' not found in workspace", fileModel.Path);
1041-
return;
1047+
return false;
10421048
}
10431049
var documentKind = _workspace.CurrentSolution.GetDocumentKind(documentId);
10441050
Guard.Against.Null(documentKind);
@@ -1050,6 +1056,7 @@ public async Task RemoveDocument(SharpIdeFile fileModel)
10501056
case TextDocumentKind.AnalyzerConfigDocument: _workspace.OnAnalyzerConfigDocumentRemoved(documentId); break;
10511057
default: throw new ArgumentOutOfRangeException(nameof(documentKind));
10521058
}
1059+
return true;
10531060
}
10541061

10551062
public async Task MoveDocument(SharpIdeFile sharpIdeFile, string oldFilePath)

src/SharpIDE.Application/Features/FileWatching/FileChangedService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ private async Task HandleCsprojChanged(SharpIdeFile file)
132132

133133
private async Task HandleWorkspaceFileChanged(SharpIdeFile file, string newContents)
134134
{
135-
await _roslynAnalysis.UpdateDocument(file, newContents);
135+
var fileUpdatedInWorkspace = await _roslynAnalysis.UpdateDocument(file, newContents);
136+
if (fileUpdatedInWorkspace is false) return;
136137
GlobalEvents.Instance.SolutionAltered.InvokeParallelFireAndForget();
137138
_updateSolutionDiagnosticsQueue.AddWork();
138139
}
@@ -146,7 +147,8 @@ private async Task HandleWorkspaceFileAdded(SharpIdeFile file, string contents)
146147

147148
private async Task HandleWorkspaceFileRemoved(SharpIdeFile file)
148149
{
149-
await _roslynAnalysis.RemoveDocument(file);
150+
var success = await _roslynAnalysis.RemoveDocument(file);
151+
if (success is false) return;
150152
GlobalEvents.Instance.SolutionAltered.InvokeParallelFireAndForget();
151153
_updateSolutionDiagnosticsQueue.AddWork();
152154
}

0 commit comments

Comments
 (0)