Skip to content

Commit

Permalink
Merge pull request #64355 from dotnet/merges/release/dev17.4-to-main
Browse files Browse the repository at this point in the history
Merge release/dev17.4 to main
  • Loading branch information
dotnet-bot authored Sep 29, 2022
2 parents b712223 + 9cb1b85 commit 6452bca
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
17 changes: 11 additions & 6 deletions src/VisualStudio/Core/Def/ProjectSystem/VisualStudioProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -991,14 +991,19 @@ private OneOrMany<string> GetMappedAnalyzerPaths(string fullPath)
if (fullPath.LastIndexOf(s_razorSourceGeneratorSdkDirectory, StringComparison.OrdinalIgnoreCase) + s_razorSourceGeneratorSdkDirectory.Length - 1 ==
fullPath.LastIndexOf(Path.DirectorySeparatorChar))
{
if (fullPath.EndsWith(s_razorSourceGeneratorMainAssemblyRootedFileName, StringComparison.OrdinalIgnoreCase))
var vsixRazorAnalyzers = _vsixAnalyzerProvider.GetAnalyzerReferencesInExtensions().SelectAsArray(
predicate: item => item.extensionId == RazorVsixExtensionId,
selector: item => item.reference.FullPath);

if (!vsixRazorAnalyzers.IsEmpty)
{
return OneOrMany.Create(_vsixAnalyzerProvider.GetAnalyzerReferencesInExtensions().SelectAsArray(
predicate: item => item.extensionId == RazorVsixExtensionId,
selector: item => item.reference.FullPath));
}
if (fullPath.EndsWith(s_razorSourceGeneratorMainAssemblyRootedFileName, StringComparison.OrdinalIgnoreCase))
{
return OneOrMany.Create(vsixRazorAnalyzers);
}

return OneOrMany.Create(ImmutableArray<string>.Empty);
return OneOrMany.Create(ImmutableArray<string>.Empty);
}
}

return OneOrMany.Create(fullPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim
End Function

<WpfFact>
Public Async Function RazorSourceGenerator() As Task
Public Async Function RazorSourceGenerator_FromVsix() As Task
Using environment = New TestEnvironment()
Dim providerFactory = DirectCast(environment.ExportProvider.GetExportedValue(Of IVisualStudioDiagnosticAnalyzerProviderFactory), MockVisualStudioDiagnosticAnalyzerProviderFactory)
providerFactory.Extensions =
Expand Down Expand Up @@ -142,7 +142,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim

Assert.Empty(environment.Workspace.CurrentSolution.Projects.Single().AnalyzerReferences)

' add Razor source generator and a couple more other analyzer filess:
' add Razor source generator and a couple more other analyzer files:
project.AddAnalyzerReference(Path.Combine(TempRoot.Root, "Sdks", "Microsoft.NET.Sdk.Razor", "source-generators", "SdkDependency1.dll"))
project.AddAnalyzerReference(Path.Combine(TempRoot.Root, "Sdks", "Microsoft.NET.Sdk.Razor", "source-generators", "Microsoft.NET.Sdk.Razor.SourceGenerators.dll"))
project.AddAnalyzerReference(Path.Combine(TempRoot.Root, "Some other directory", "Microsoft.NET.Sdk.Razor.SourceGenerators.dll"))
Expand Down Expand Up @@ -193,6 +193,32 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim
End Using
End Function

<WpfFact>
Public Async Function RazorSourceGenerator_FromSdk() As Task
Using environment = New TestEnvironment()
Dim providerFactory = DirectCast(environment.ExportProvider.GetExportedValue(Of IVisualStudioDiagnosticAnalyzerProviderFactory), MockVisualStudioDiagnosticAnalyzerProviderFactory)
providerFactory.Extensions =
{
({
Path.Combine(TempRoot.Root, "File.dll")
},
"AnotherExtension")
}

Dim project = Await environment.ProjectFactory.CreateAndAddToWorkspaceAsync(
"Project", LanguageNames.CSharp, CancellationToken.None)

' add Razor source generator and a couple more other analyzer filess:
Dim path1 = Path.Combine(TempRoot.Root, "Sdks", "Microsoft.NET.Sdk.Razor", "source-generators", "Microsoft.NET.Sdk.Razor.SourceGenerators.dll")
Dim path2 = Path.Combine(TempRoot.Root, "Sdks", "Microsoft.NET.Sdk.Razor", "source-generators", "SdkDependency1.dll")
project.AddAnalyzerReference(path1)
project.AddAnalyzerReference(path2)

AssertEx.Equal({path1, path2}, environment.Workspace.CurrentSolution.Projects.Single().AnalyzerReferences.Select(Function(r) r.FullPath))

End Using
End Function

Private Shared Async Function GetDiagnostics(environment As TestEnvironment) As Task(Of ImmutableArray(Of DiagnosticData))
' Wait for diagnostics to be updated asynchronously
Dim waiter = environment.ExportProvider.GetExportedValue(Of AsynchronousOperationListenerProvider).GetWaiter(FeatureAttribute.DiagnosticService)
Expand Down

0 comments on commit 6452bca

Please sign in to comment.