Skip to content

Commit b570dc0

Browse files
jaredparjjonescz
andauthored
Feedback from analyzer loading change (#77780)
* Feedback from analyzer loading change Few changes here: 1. Jason had suggested I add an assert into the shadow copy loader, I did but apparently forgot to save. 2. Rename the file to match type name Follow up to #77004 * PR feedback * Apply suggestions from code review Co-authored-by: Jan Jones <[email protected]> --------- Co-authored-by: Jan Jones <[email protected]>
1 parent 61f311f commit b570dc0

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/Compilers/Core/Portable/DiagnosticAnalyzer/ShadowCopyAnalyzerAssemblyLoader.cs renamed to src/Compilers/Core/Portable/DiagnosticAnalyzer/ShadowCopyAnalyzerPathResolver.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Collections.Immutable;
1313
using System.Reflection;
1414
using System.Globalization;
15+
using System.Diagnostics;
1516

1617
namespace Microsoft.CodeAnalysis
1718
{
@@ -52,7 +53,7 @@ internal sealed class ShadowCopyAnalyzerPathResolver : IAnalyzerPathResolver
5253
/// is a map between the original path and the Task that completes when the shadow copy for that
5354
/// original path completes.
5455
/// </summary>
55-
private ConcurrentDictionary<string, Task> CopyMap { get; } = new(AnalyzerAssemblyLoader.OriginalPathComparer);
56+
private ConcurrentDictionary<string, Task<string>> CopyMap { get; } = new(AnalyzerAssemblyLoader.OriginalPathComparer);
5657

5758
/// <summary>
5859
/// This is the number of shadow copies that have occurred in this instance.
@@ -198,15 +199,15 @@ private void ShadowCopyFile(string originalFilePath, string shadowCopyPath)
198199
return;
199200
}
200201

201-
var tcs = new TaskCompletionSource<object?>();
202+
var tcs = new TaskCompletionSource<string>();
202203
var task = CopyMap.GetOrAdd(originalFilePath, tcs.Task);
203204
if (object.ReferenceEquals(task, tcs.Task))
204205
{
205206
// This thread won and we need to do the copy.
206207
try
207208
{
208209
copyFile(originalFilePath, shadowCopyPath);
209-
tcs.SetResult(null);
210+
tcs.SetResult(shadowCopyPath);
210211
}
211212
catch (Exception ex)
212213
{
@@ -218,6 +219,7 @@ private void ShadowCopyFile(string originalFilePath, string shadowCopyPath)
218219
{
219220
// This thread lost and we need to wait for the winner to finish the copy.
220221
task.Wait();
222+
Debug.Assert(AnalyzerAssemblyLoader.GeneratedPathComparer.Equals(shadowCopyPath, task.Result));
221223
}
222224

223225
static void copyFile(string originalPath, string shadowCopyPath)

src/Workspaces/Core/Portable/Microsoft.CodeAnalysis.Workspaces.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<Compile Include="..\..\..\Compilers\Core\Portable\DiagnosticAnalyzer\AnalyzerAssemblyLoader.cs" Link="Diagnostics\CompilerShared\AnalyzerAssemblyLoader.cs" />
3838
<Compile Include="..\..\..\Compilers\Core\Portable\DiagnosticAnalyzer\AnalyzerAssemblyLoader.Core.cs" Link="Diagnostics\CompilerShared\AnalyzerAssemblyLoader.Core.cs" />
3939
<Compile Include="..\..\..\Compilers\Core\Portable\DiagnosticAnalyzer\AnalyzerAssemblyLoader.Desktop.cs" Link="Diagnostics\CompilerShared\AnalyzerAssemblyLoader.Desktop.cs" />
40-
<Compile Include="..\..\..\Compilers\Core\Portable\DiagnosticAnalyzer\ShadowCopyAnalyzerAssemblyLoader.cs" Link="Diagnostics\CompilerShared\ShadowCopyAnalyzerAssemblyLoader.cs" />
40+
<Compile Include="..\..\..\Compilers\Core\Portable\DiagnosticAnalyzer\ShadowCopyAnalyzerPathResolver.cs" Link="Diagnostics\CompilerShared\ShadowCopyAnalyzerPathResolver.cs" />
4141
<Compile Include="..\..\..\Compilers\Core\Portable\DiagnosticAnalyzer\IAnalyzerAssemblyResolver.cs" Link="Diagnostics\CompilerShared\IAnalyzerAssemblyResolver.cs" />
4242
<Compile Include="..\..\..\Compilers\Core\Portable\DiagnosticAnalyzer\IAnalyzerPathResolver.cs" Link="Diagnostics\CompilerShared\IAnalyzerAssemblyResolver.cs" />
4343
<Compile Include="..\..\..\Compilers\Core\Portable\DiagnosticAnalyzer\ProgramFilesAnalyzerPathResolver.cs" Link="Diagnostics\CompilerShared\ProgramFilesAnalyzerPathResolver.cs" />

0 commit comments

Comments
 (0)