Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<!-- Avoid compile error about missing namespace when combining ImplicitUsings with .NET Framework target frameworks. -->
<Using Remove="System.Net.Http" Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'" />
</ItemGroup>
<Import Project="Directory.Packages.Analyzers.props" Condition="'$(IsAnalyzerProject)'=='true'" />
</Project>
19 changes: 19 additions & 0 deletions Directory.Packages.Analyzers.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project>
<PropertyGroup>
<CodeAnalysisVersionForAnalyzers>3.11.0</CodeAnalysisVersionForAnalyzers>
</PropertyGroup>
<ItemGroup>
<!-- These versions carefully chosen to support VS 2019 Update 11. -->
<PackageVersion Update="Microsoft.CodeAnalysis" Version="$(CodeAnalysisVersionForAnalyzers)" />
<PackageVersion Update="Microsoft.CodeAnalysis.Common" Version="$(CodeAnalysisVersionForAnalyzers)" />
<PackageVersion Update="Microsoft.CodeAnalysis.CSharp" Version="$(CodeAnalysisVersionForAnalyzers)" />
<PackageVersion Update="Microsoft.CodeAnalysis.CSharp.Workspaces" version="$(CodeAnalysisVersionForAnalyzers)" />
<PackageVersion Update="Microsoft.CodeAnalysis.VisualBasic" version="$(CodeAnalysisVersionForAnalyzers)" />
<PackageVersion Update="Microsoft.CodeAnalysis.VisualBasic.Workspaces" version="$(CodeAnalysisVersionForAnalyzers)" />
<PackageVersion Update="System.Collections.Immutable" Version="5.0.0" />
<PackageVersion Update="System.Memory" Version="4.5.4" />
<PackageVersion Update="System.Reflection.Metadata" Version="5.0.0" />
<PackageVersion Update="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
<PackageVersion Update="System.Text.Json" Version="4.7.2" />
</ItemGroup>
</Project>
14 changes: 11 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@
<MicrosoftTestingPlatformVersion>2.0.2</MicrosoftTestingPlatformVersion>

<MicroBuildVersion>2.0.208</MicroBuildVersion>
<CodeAnalysisVersion>4.12.0</CodeAnalysisVersion>
<CodefixTestingVersion>1.1.2</CodefixTestingVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.12.6" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.1.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="3.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" version="$(CodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="$(CodefixTestingVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" version="$(CodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="$(CodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic" version="$(CodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.CodeFix.Testing.XUnit" Version="$(CodefixTestingVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" version="$(CodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis" Version="$(CodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.VisualStudio.Designer.Interfaces" Version="17.12.40391" />
<PackageVersion Include="Microsoft.VisualStudio.Shell.15.0" Version="17.12.40392" />
<PackageVersion Include="Microsoft.VisualStudio.Shell.Framework" Version="17.12.40391" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
Diagnostic diagnostic = context.Diagnostics.First();
SyntaxNode? root = await context.Document.GetSyntaxRootAsync(context.CancellationToken);
SyntaxNode? node = root?.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie: true);
if (root is null || diagnostic.AdditionalLocations.Count == 0)
{
return;
}

// The first additional location points to the assignment target or variable declarator.
SyntaxNode? node = root.FindNode(diagnostic.AdditionalLocations[0].SourceSpan, getInnermostNodeForTie: true);
if (node != null)
{
SyntaxNode? presentArgument = node is VariableDeclaratorSyntax declaratorSyntax ? SyntaxFactory.IdentifierName(declaratorSyntax.Identifier)
: node.Parent is InvocationExpressionSyntax ? null // direct GetService result invocation
: node is NameSyntax ? node
: node is MemberAccessExpressionSyntax ? node
: null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.Shell.15.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Framework" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.Threading" PrivateAssets="all" />

<!-- Avoid dependencies on earlier insecure Newtownsoft.Json, exclude "Compile" assets since we don't package Newtonsoft.Json (or any Microsoft.VisualStudio.* assembly) with the analyzer -->
<PackageReference Include="Newtonsoft.Json" ExcludeAssets="Compile" />
</ItemGroup>

</Project>
52 changes: 21 additions & 31 deletions src/Microsoft.VisualStudio.SDK.Analyzers/Namespaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,87 +14,77 @@ internal static class Namespaces
/// <summary>
/// Gets an array for each element in the namespace Microsoft.
/// </summary>
internal static readonly ImmutableArray<string> Microsoft = [
nameof(Microsoft),
];
internal static readonly ImmutableArray<string> Microsoft = ImmutableArray.Create(
nameof(Microsoft));

/// <summary>
/// Gets an array for each element in the namespace Microsoft.VisualStudio.Shell.
/// </summary>
internal static readonly ImmutableArray<string> MicrosoftVisualStudioShell = [
internal static readonly ImmutableArray<string> MicrosoftVisualStudioShell = ImmutableArray.Create(
nameof(Microsoft),
nameof(VisualStudio),
nameof(Shell),
];
"Shell");

/// <summary>
/// Gets an array for each element in the namespace Microsoft.VisualStudio.Shell.Interop.
/// </summary>
internal static readonly ImmutableArray<string> MicrosoftVisualStudioShellInterop = [
internal static readonly ImmutableArray<string> MicrosoftVisualStudioShellInterop = ImmutableArray.Create(
nameof(Microsoft),
nameof(VisualStudio),
nameof(Shell),
nameof(Shell.Interop),
];
"Shell",
"Interop");

/// <summary>
/// Gets an array for each element in the namespace Microsoft.VisualStudio.OLE.Interop.
/// </summary>
internal static readonly ImmutableArray<string> MicrosoftVisualStudioOLEInterop = [
internal static readonly ImmutableArray<string> MicrosoftVisualStudioOLEInterop = ImmutableArray.Create(
nameof(Microsoft),
nameof(VisualStudio),
"OLE",
"Interop",
];
"Interop");

/// <summary>
/// Gets an array for each element in the namespace Microsoft.VisualStudio.Threading.
/// </summary>
internal static readonly ImmutableArray<string> MicrosoftVisualStudioThreading = [
internal static readonly ImmutableArray<string> MicrosoftVisualStudioThreading = ImmutableArray.Create(
nameof(Microsoft),
nameof(VisualStudio),
nameof(Threading),
];
"Threading");

/// <summary>
/// Gets an array for each element in the namespace System.
/// </summary>
internal static readonly ImmutableArray<string> System = [
nameof(System),
];
internal static readonly ImmutableArray<string> System = ImmutableArray.Create(
nameof(System));

/// <summary>
/// Gets an array for each element in the namespace System.Threading.
/// </summary>
internal static readonly ImmutableArray<string> SystemThreading = [
internal static readonly ImmutableArray<string> SystemThreading = ImmutableArray.Create(
nameof(System),
nameof(global::System.Threading),
];
nameof(global::System.Threading));

/// <summary>
/// Gets an array for each element in the namespace System.Threading.Tasks.
/// </summary>
internal static readonly ImmutableArray<string> SystemThreadingTasks = [
internal static readonly ImmutableArray<string> SystemThreadingTasks = ImmutableArray.Create(
nameof(System),
nameof(global::System.Threading),
nameof(global::System.Threading.Tasks),
];
nameof(global::System.Threading.Tasks));

/// <summary>
/// Gets an array for each element in the namespace System.ComponentModel.Composition.
/// </summary>
internal static readonly ImmutableArray<string> SystemComponentModelComposition = [
internal static readonly ImmutableArray<string> SystemComponentModelComposition = ImmutableArray.Create(
nameof(System),
nameof(global::System.ComponentModel),
nameof(global::System.ComponentModel.Composition),
];
"Composition");

/// <summary>
/// Gets an array for each element in the namespace System.Composition.
/// </summary>
internal static readonly ImmutableArray<string> SystemComposition = [
internal static readonly ImmutableArray<string> SystemComposition = ImmutableArray.Create(
nameof(System),
nameof(global::System.Composition),
];
"Composition");
}
}
Loading
Loading