From 8455a2307b5e9da495de6c726d29564a12df6b07 Mon Sep 17 00:00:00 2001 From: David Zidar Date: Tue, 25 Jan 2022 00:43:29 +0100 Subject: [PATCH] Fix concurrency issue in CSharpDiagnosticWorker List is not thread safe, use ImmutableList and ImmutableInterlocked like CSharpDiagnosticWorkerWithAnalyzers does. --- .../Workers/Diagnostics/CSharpDiagnosticWorker.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticWorker.cs b/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticWorker.cs index 56f6e9fa88..494072c396 100644 --- a/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticWorker.cs +++ b/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticWorker.cs @@ -141,7 +141,7 @@ public async Task> GetDiagnostics(ImmutableA { if (!documentPaths.Any()) return ImmutableArray.Empty; - var results = new List(); + var results = ImmutableList.Empty; var documents = (await Task.WhenAll( @@ -164,7 +164,8 @@ public async Task> GetDiagnostics(ImmutableA try { var diagnostics = await GetDiagnosticsForDocument(document, projectName); - results.Add(new DocumentDiagnostics(document.Id, document.FilePath, document.Project.Id, document.Project.Name, diagnostics)); + var documentDiagnostics = new DocumentDiagnostics(document.Id, document.FilePath, document.Project.Id, document.Project.Name, diagnostics); + ImmutableInterlocked.Update(ref results, currentResults => currentResults.Add(documentDiagnostics)); } finally {