Skip to content

Commit

Permalink
CodeFix project: generate comment instead of opening browser; Vsix: A…
Browse files Browse the repository at this point in the history
…uto version number; Update dependencies.
  • Loading branch information
fryderykhuang committed Jan 30, 2024
1 parent 20ed6dd commit e852f3f
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 147 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Currently this project contains 3 main components:
### Setup

1. Install NuGet package `NullGC.Allocators` and `NullGC.Linq`
2. If your IDE is VS2022 or above, Install `NullGC.Analyzer` VS extension, otherwise, install the same name NuGet package. (For LINQ operation boxing detection and value type lifetime enforcement)
2. If your IDE is VS2022 or above, Install `NullGC.Analyzer` VS extension, otherwise, install the same name NuGet package. (For LINQ operation boxing detection and value type lifetime enforcement, the warning codes produced are prefixed with `NGC`)
3. Setup AllocatorContext:

```csharp
Expand Down
4 changes: 2 additions & 2 deletions src/NullGC.Allocators.Tests/NullGC.Allocators.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
3 changes: 1 addition & 2 deletions src/NullGC.Analyzer.CodeFixes/CodeFixResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/NullGC.Analyzer.CodeFixes/CodeFixResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@
<value>Submit feature request</value>
</data>
<data name="NGC20_Title" xml:space="preserve">
<value>Add call to Borrow();</value>
<value>Add call to Borrow()</value>
</data>
</root>
69 changes: 31 additions & 38 deletions src/NullGC.Analyzer.CodeFixes/NullGCAnalyzerCodeFixProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed override FixAllProvider GetFixAllProvider()
return WellKnownFixAllProviders.BatchFixer;
}

public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
{
foreach (var diag in context.Diagnostics)
if (diag.Id == NullGCAnalyzer.BoxingOnNotImplementedLinqOperationDiagnosticId)
Expand All @@ -38,7 +38,6 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
c => ReportAsync(context, diag, c),
nameof(CodeFixResources.NGC12_Title)),
diag);
return;
}
else if (diag.Id == NullGCAnalyzer.ShouldBorrowDiagnosticId)
{
Expand All @@ -50,9 +49,10 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
diag);
}

return Task.CompletedTask;
}

private Task<Solution> ReportAsync(CodeFixContext context, Diagnostic diag, CancellationToken c)
private async Task<Solution> ReportAsync(CodeFixContext context, Diagnostic diag, CancellationToken c)
{
var title = $"[LINQ] Linq operator '{diag.Properties["OperatorName"]}' is not implemented.";
var body = @$"InputSignature:
Expand All @@ -66,50 +66,43 @@ private Task<Solution> ReportAsync(CodeFixContext context, Diagnostic diag, Canc
Comment:
";

Process.Start(@$"https://github.com/fryderykhuang/NullGC/issues/new?template=linq-operation-not-implemented.md&title={WebUtility.UrlEncode(title)}&body={WebUtility.UrlEncode(body)}");
return Task.FromResult(context.Document.Project.Solution);
var url =
@$"https://github.com/fryderykhuang/NullGC/issues/new?template=linq-operation-not-implemented.md&title={WebUtility.UrlEncode(title)}&body={WebUtility.UrlEncode(body)}";
// Duplicate execution in VS, error in Rider
// try
// {
// Process.Start(url);
// }
// catch
{
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
var node = root?.FindNode(diag.Location.SourceSpan);
if (node is not null)
{
return context.Document.WithSyntaxRoot(root.ReplaceNode(node,
node.WithLeadingTrivia(node.GetLeadingTrivia()
.Add(SyntaxFactory.Comment(@$"/*
Click to submit a feature request:
{url}
*/"))))).Project
.Solution;
}
}

return context.Document.Project.Solution;
}

private async Task<Solution> AddCallToBorrowAsync(CodeFixContext context, Diagnostic diag, CancellationToken cancellationToken)
{
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
var node = root.FindNode(diag.Location.SourceSpan);

if (node is ArgumentSyntax argSyntax)
if (root?.FindNode(diag.Location.SourceSpan) is ArgumentSyntax argSyntax)
{
var updatedArgSyntax = SyntaxFactory.Argument(SyntaxFactory.InvocationExpression(SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, argSyntax.Expression, SyntaxFactory.IdentifierName("Borrow"))));
var updatedArgSyntax = SyntaxFactory.Argument(SyntaxFactory.InvocationExpression(
SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, argSyntax.Expression,
SyntaxFactory.IdentifierName("Borrow"))));
return context.Document.WithSyntaxRoot(root.ReplaceNode(argSyntax, updatedArgSyntax)).Project.Solution;
}

return context.Document.Project.Solution;

//var sm = await context.Document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
//if (sm != null)
//{
// var syminfo = sm.GetSymbolInfo(node, cancellationToken);
// if (syminfo.Symbol is IParameterSymbol prmSym)
// {
// prmSym.
// }

//}

//// Compute new uppercase name.
//var identifierToken = typeDecl.Identifier;
//var newName = identifierToken.Text.ToUpperInvariant();

//// Get the symbol representing the type to be renamed.
//var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
//var typeSymbol = semanticModel.GetDeclaredSymbol(typeDecl, cancellationToken);

//// Produce a new solution that has all references to that type renamed, including the declaration.
//var originalSolution = document.Project.Solution;
//var optionSet = originalSolution.Workspace.Options;
//var newSolution = await Renamer
// .RenameSymbolAsync(document.Project.Solution, typeSymbol, newName, optionSet, cancellationToken)
// .ConfigureAwait(false);

//// Return the new solution with the now-uppercase type name.
//return newSolution;
}
}
128 changes: 69 additions & 59 deletions src/NullGC.Analyzer.Vsix/NullGC.Analyzer.Vsix.csproj
Original file line number Diff line number Diff line change
@@ -1,63 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>NullGC.Analyzer.Vsix</RootNamespace>
<AssemblyName>NullGC.Analyzer.Vsix</AssemblyName>
</PropertyGroup>

<PropertyGroup>
<GeneratePkgDefFile>false</GeneratePkgDefFile>
<IncludeAssemblyInVSIXContainer>false</IncludeAssemblyInVSIXContainer>
<IncludeDebugSymbolsInVSIXContainer>false</IncludeDebugSymbolsInVSIXContainer>
<IncludeDebugSymbolsInLocalVSIXDeployment>false</IncludeDebugSymbolsInLocalVSIXDeployment>
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
<VSSDKTargetPlatformRegRootSuffix>Roslyn</VSSDKTargetPlatformRegRootSuffix>
</PropertyGroup>

<ItemGroup>
<None Remove="..\..\README.md" />
<None Remove="..\icon.ico" />
</ItemGroup>

<ItemGroup>
<Content Include="..\..\README.md">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="..\icon.ico">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.8.2365" PrivateAssets="all" />
<PackageReference Include="Microsoft.VSSDK.VsixSignTool" Version="16.2.29116.78" />
</ItemGroup>

<PropertyGroup>
<StartAction>Program</StartAction>
<StartProgram>$(DevEnvDir)devenv.exe</StartProgram>
<StartArguments>/rootsuffix $(VSSDKTargetPlatformRegRootSuffix)</StartArguments>
</PropertyGroup>

<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />

<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="Exists('$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets')" />

<ItemGroup>
<ProjectReference Include="..\NullGC.Analyzer.CodeFixes\NullGC.Analyzer.CodeFixes.csproj" />
<ProjectReference Include="..\NullGC.Analyzer\NullGC.Analyzer.csproj" />
</ItemGroup>

<ItemGroup>
<!-- https://github.com/dotnet/sdk/issues/433 -->
<ProjectReference Update="@(ProjectReference)" AdditionalProperties="TargetFramework=netstandard2.0" />

<!-- https://github.com/Microsoft/extendvs/issues/57 -->
<ProjectReference Update="@(ProjectReference)" Name="%(Filename)" />
</ItemGroup>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props"/>

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>NullGC.Analyzer.Vsix</RootNamespace>
<AssemblyName>NullGC.Analyzer.Vsix</AssemblyName>
</PropertyGroup>

<PropertyGroup>
<GeneratePkgDefFile>false</GeneratePkgDefFile>
<IncludeAssemblyInVSIXContainer>false</IncludeAssemblyInVSIXContainer>
<IncludeDebugSymbolsInVSIXContainer>false</IncludeDebugSymbolsInVSIXContainer>
<IncludeDebugSymbolsInLocalVSIXDeployment>false</IncludeDebugSymbolsInLocalVSIXDeployment>
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
<VSSDKTargetPlatformRegRootSuffix>Roslyn</VSSDKTargetPlatformRegRootSuffix>
</PropertyGroup>

<ItemGroup>
<None Remove="..\..\README.md"/>
<None Remove="..\icon.ico"/>
</ItemGroup>

<ItemGroup>
<Content Include="..\..\README.md">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="..\icon.ico">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.8.2365" PrivateAssets="all"/>
<PackageReference Include="Microsoft.VSSDK.VsixSignTool" Version="16.2.29116.78"/>
</ItemGroup>

<PropertyGroup>
<StartAction>Program</StartAction>
<StartProgram>$(DevEnvDir)devenv.exe</StartProgram>
<StartArguments>/rootsuffix $(VSSDKTargetPlatformRegRootSuffix)</StartArguments>
</PropertyGroup>

<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets"/>

<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="Exists('$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets')"/>

<ItemGroup>
<ProjectReference Include="..\NullGC.Analyzer\NullGC.Analyzer.csproj"/>
<ProjectReference Include="..\NullGC.Analyzer.CodeFixes\NullGC.Analyzer.CodeFixes.csproj" />
</ItemGroup>

<ItemGroup>
<!-- https://github.com/dotnet/sdk/issues/433 -->
<ProjectReference Update="@(ProjectReference)" AdditionalProperties="TargetFramework=netstandard2.0"/>

<!-- https://github.com/Microsoft/extendvs/issues/57 -->
<ProjectReference Update="@(ProjectReference)" Name="%(Filename)"/>
</ItemGroup>

<!--https://stackoverflow.com/a/24328739-->
<Target Name="UpdateVersionInVsixManifest" BeforeTargets="PrepareForBuild" Condition="$(Version) != ''">
<Message Text="Updating VSIX Version"/>
<XmlPoke
XmlInputPath="source.extension.vsixmanifest"
Query="/n:PackageManifest/n:Metadata/n:Identity/@Version"
Value="$(Version)"
Namespaces="&lt;Namespace Prefix='n' Uri='http://schemas.microsoft.com/developer/vsx-schema/2011' Name='DoNotKnowWhatThisIsFor-ButItIsRequired' /&gt;">
</XmlPoke>
</Target>
</Project>
58 changes: 29 additions & 29 deletions src/NullGC.Analyzer.Vsix/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="NullGC.Analyzer.7cfb097e-ba96-48ef-a036-13a39301d869" Version="0.63" Language="en-US" Publisher="Fryderyk Huang"/>
<DisplayName>NullGC.Analyzer</DisplayName>
<Description xml:space="preserve">Analyzer and code fixer for NullGC high performance utility library</Description>
<MoreInfo>https://github.com/fryderykhuang/NullGC</MoreInfo>
<Icon>icon.ico</Icon>
</Metadata>
<Installation>
<InstallationTarget Version="[17.0,18.0)" Id="Microsoft.VisualStudio.Community">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.0,18.0)" Id="Microsoft.VisualStudio.Enterprise">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="NullGC.Analyzer" Path="|NullGC.Analyzer|"/>
<Asset Type="Microsoft.VisualStudio.Analyzer" d:Source="Project" d:ProjectName="NullGC.Analyzer" Path="|NullGC.Analyzer|"/>
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="NullGC.Analyzer.CodeFixes" Path="|NullGC.Analyzer.CodeFixes|"/>
<Asset Type="Microsoft.VisualStudio.Analyzer" d:Source="Project" d:ProjectName="NullGC.Analyzer.CodeFixes" Path="|NullGC.Analyzer.CodeFixes|"/>
</Assets>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0,)" DisplayName="Visual Studio core editor" />
<Prerequisite Id="Microsoft.VisualStudio.Component.Roslyn.LanguageServices" Version="[15.0,)" DisplayName="Roslyn Language Services" />
</Prerequisites>
<Metadata>
<Identity Id="NullGC.Analyzer.7cfb097e-ba96-48ef-a036-13a39301d869" Version="1.0.0" Language="en-US" Publisher="Fryderyk Huang" />
<DisplayName>NullGC.Analyzer</DisplayName>
<Description xml:space="preserve">Analyzer and code fixer for NullGC high performance utility library</Description>
<MoreInfo>https://github.com/fryderykhuang/NullGC</MoreInfo>
<Icon>icon.ico</Icon>
</Metadata>
<Installation>
<InstallationTarget Version="[17.0,18.0)" Id="Microsoft.VisualStudio.Community">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.0,18.0)" Id="Microsoft.VisualStudio.Enterprise">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="NullGC.Analyzer" Path="|NullGC.Analyzer|" />
<Asset Type="Microsoft.VisualStudio.Analyzer" d:Source="Project" d:ProjectName="NullGC.Analyzer" Path="|NullGC.Analyzer|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="NullGC.Analyzer.CodeFixes" Path="|NullGC.Analyzer.CodeFixes|" />
<Asset Type="Microsoft.VisualStudio.Analyzer" d:Source="Project" d:ProjectName="NullGC.Analyzer.CodeFixes" Path="|NullGC.Analyzer.CodeFixes|" />
</Assets>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0,)" DisplayName="Visual Studio core editor" />
<Prerequisite Id="Microsoft.VisualStudio.Component.Roslyn.LanguageServices" Version="[15.0,)" DisplayName="Roslyn Language Services" />
</Prerequisites>
</PackageManifest>
2 changes: 1 addition & 1 deletion src/NullGC.Analyzer/NullGC.Analyzer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit e852f3f

Please sign in to comment.