From e852f3f7708efd07e5fef67db2800d2f872a429e Mon Sep 17 00:00:00 2001 From: Fryderyk Huang Date: Tue, 30 Jan 2024 22:13:30 +0800 Subject: [PATCH] CodeFix project: generate comment instead of opening browser; Vsix: Auto version number; Update dependencies. --- README.md | 2 +- .../NullGC.Allocators.Tests.csproj | 4 +- .../CodeFixResources.Designer.cs | 3 +- .../CodeFixResources.resx | 2 +- .../NullGCAnalyzerCodeFixProvider.cs | 69 +++++----- .../NullGC.Analyzer.Vsix.csproj | 128 ++++++++++-------- .../source.extension.vsixmanifest | 58 ++++---- src/NullGC.Analyzer/NullGC.Analyzer.csproj | 2 +- src/NullGC.Analyzer/Resources.Designer.cs | 9 +- src/NullGC.Analyzer/Resources.resx | 8 +- .../NullGC.Collections.Tests.csproj | 4 +- .../NullGC.Linq.Tests.csproj | 4 +- .../NullGC.TestCommons.csproj | 2 +- 13 files changed, 148 insertions(+), 147 deletions(-) diff --git a/README.md b/README.md index 056b421..d1ee42d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/NullGC.Allocators.Tests/NullGC.Allocators.Tests.csproj b/src/NullGC.Allocators.Tests/NullGC.Allocators.Tests.csproj index 0bc7c58..190fa6e 100644 --- a/src/NullGC.Allocators.Tests/NullGC.Allocators.Tests.csproj +++ b/src/NullGC.Allocators.Tests/NullGC.Allocators.Tests.csproj @@ -14,8 +14,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/NullGC.Analyzer.CodeFixes/CodeFixResources.Designer.cs b/src/NullGC.Analyzer.CodeFixes/CodeFixResources.Designer.cs index 076d38d..de8cbbe 100644 --- a/src/NullGC.Analyzer.CodeFixes/CodeFixResources.Designer.cs +++ b/src/NullGC.Analyzer.CodeFixes/CodeFixResources.Designer.cs @@ -1,7 +1,6 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -70,7 +69,7 @@ internal static string NGC12_Title { } /// - /// Looks up a localized string similar to Add call to Borrow();. + /// Looks up a localized string similar to Add call to Borrow(). /// internal static string NGC20_Title { get { diff --git a/src/NullGC.Analyzer.CodeFixes/CodeFixResources.resx b/src/NullGC.Analyzer.CodeFixes/CodeFixResources.resx index b3691a3..8433176 100644 --- a/src/NullGC.Analyzer.CodeFixes/CodeFixResources.resx +++ b/src/NullGC.Analyzer.CodeFixes/CodeFixResources.resx @@ -121,6 +121,6 @@ Submit feature request - Add call to Borrow(); + Add call to Borrow() \ No newline at end of file diff --git a/src/NullGC.Analyzer.CodeFixes/NullGCAnalyzerCodeFixProvider.cs b/src/NullGC.Analyzer.CodeFixes/NullGCAnalyzerCodeFixProvider.cs index 137cb6e..da5f98f 100644 --- a/src/NullGC.Analyzer.CodeFixes/NullGCAnalyzerCodeFixProvider.cs +++ b/src/NullGC.Analyzer.CodeFixes/NullGCAnalyzerCodeFixProvider.cs @@ -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) @@ -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) { @@ -50,9 +49,10 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) diag); } + return Task.CompletedTask; } - private Task ReportAsync(CodeFixContext context, Diagnostic diag, CancellationToken c) + private async Task ReportAsync(CodeFixContext context, Diagnostic diag, CancellationToken c) { var title = $"[LINQ] Linq operator '{diag.Properties["OperatorName"]}' is not implemented."; var body = @$"InputSignature: @@ -66,50 +66,43 @@ private Task 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 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; } } \ No newline at end of file diff --git a/src/NullGC.Analyzer.Vsix/NullGC.Analyzer.Vsix.csproj b/src/NullGC.Analyzer.Vsix/NullGC.Analyzer.Vsix.csproj index 688316d..7b7fcf7 100644 --- a/src/NullGC.Analyzer.Vsix/NullGC.Analyzer.Vsix.csproj +++ b/src/NullGC.Analyzer.Vsix/NullGC.Analyzer.Vsix.csproj @@ -1,63 +1,73 @@ - - - - netstandard2.0 - NullGC.Analyzer.Vsix - NullGC.Analyzer.Vsix - - - - false - false - false - false - false - false - Roslyn - - - - - - - - - - true - - - true - - - - - - - - - - Program - $(DevEnvDir)devenv.exe - /rootsuffix $(VSSDKTargetPlatformRegRootSuffix) - - - - - - - - - - - - - - - - - - + + + netstandard2.0 + NullGC.Analyzer.Vsix + NullGC.Analyzer.Vsix + + + + false + false + false + false + false + false + Roslyn + + + + + + + + + + true + + + true + + + + + + + + + + Program + $(DevEnvDir)devenv.exe + /rootsuffix $(VSSDKTargetPlatformRegRootSuffix) + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/NullGC.Analyzer.Vsix/source.extension.vsixmanifest b/src/NullGC.Analyzer.Vsix/source.extension.vsixmanifest index 8b2bb90..223ae07 100644 --- a/src/NullGC.Analyzer.Vsix/source.extension.vsixmanifest +++ b/src/NullGC.Analyzer.Vsix/source.extension.vsixmanifest @@ -1,31 +1,31 @@ - + - - - NullGC.Analyzer - Analyzer and code fixer for NullGC high performance utility library - https://github.com/fryderykhuang/NullGC - icon.ico - - - - amd64 - - - amd64 - - - - - - - - - - - - - - - + + + NullGC.Analyzer + Analyzer and code fixer for NullGC high performance utility library + https://github.com/fryderykhuang/NullGC + icon.ico + + + + amd64 + + + amd64 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/NullGC.Analyzer/NullGC.Analyzer.csproj b/src/NullGC.Analyzer/NullGC.Analyzer.csproj index 5e08b7e..4afd99b 100644 --- a/src/NullGC.Analyzer/NullGC.Analyzer.csproj +++ b/src/NullGC.Analyzer/NullGC.Analyzer.csproj @@ -14,7 +14,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/NullGC.Analyzer/Resources.Designer.cs b/src/NullGC.Analyzer/Resources.Designer.cs index 9239619..858b7a5 100644 --- a/src/NullGC.Analyzer/Resources.Designer.cs +++ b/src/NullGC.Analyzer/Resources.Designer.cs @@ -1,7 +1,6 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -97,7 +96,7 @@ internal static string NGC11_Description { } /// - /// Looks up a localized string similar to Linq struct '{0}' will be boxed to '{1}' at runtime. + /// Looks up a localized string similar to LINQ struct '{0}' will be boxed to '{1}' at runtime. /// internal static string NGC11_MessageFormat { get { @@ -106,7 +105,7 @@ internal static string NGC11_MessageFormat { } /// - /// Looks up a localized string similar to Linq enumerable struct will be boxed. + /// Looks up a localized string similar to LINQ chain will be boxed. /// internal static string NGC11_Title { get { @@ -124,7 +123,7 @@ internal static string NGC12_Description { } /// - /// Looks up a localized string similar to The specific overload of Linq operator '{0}' is not implemented yet, boxing will happen after fallback to system Linq. + /// Looks up a localized string similar to The specific overload of Linq operator '{0}' is not implemented yet, the LINQ chain will be boxed at runtime to be able to use as an IEnumerable. /// internal static string NGC12_MessageFormat { get { @@ -133,7 +132,7 @@ internal static string NGC12_MessageFormat { } /// - /// Looks up a localized string similar to Linq enumerable struct will be boxed. + /// Looks up a localized string similar to This LINQ operator overload is not implemented. /// internal static string NGC12_Title { get { diff --git a/src/NullGC.Analyzer/Resources.resx b/src/NullGC.Analyzer/Resources.resx index f446f29..515cece 100644 --- a/src/NullGC.Analyzer/Resources.resx +++ b/src/NullGC.Analyzer/Resources.resx @@ -130,19 +130,19 @@ - Linq struct '{0}' will be boxed to '{1}' at runtime + LINQ struct '{0}' will be boxed to '{1}' at runtime - Linq enumerable struct will be boxed + LINQ chain will be boxed - The specific overload of Linq operator '{0}' is not implemented yet, boxing will happen after fallback to system Linq + The specific overload of Linq operator '{0}' is not implemented yet, the LINQ chain will be boxed at runtime to be able to use as an IEnumerable - Linq enumerable struct will be boxed + This LINQ operator overload is not implemented diff --git a/src/NullGC.Collections.Tests/NullGC.Collections.Tests.csproj b/src/NullGC.Collections.Tests/NullGC.Collections.Tests.csproj index 276a445..d64e18f 100644 --- a/src/NullGC.Collections.Tests/NullGC.Collections.Tests.csproj +++ b/src/NullGC.Collections.Tests/NullGC.Collections.Tests.csproj @@ -13,8 +13,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/NullGC.Linq.Tests/NullGC.Linq.Tests.csproj b/src/NullGC.Linq.Tests/NullGC.Linq.Tests.csproj index b56c4a6..a303dd5 100644 --- a/src/NullGC.Linq.Tests/NullGC.Linq.Tests.csproj +++ b/src/NullGC.Linq.Tests/NullGC.Linq.Tests.csproj @@ -16,8 +16,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/NullGC.TestCommons/NullGC.TestCommons.csproj b/src/NullGC.TestCommons/NullGC.TestCommons.csproj index 4a9e143..7d33c6b 100644 --- a/src/NullGC.TestCommons/NullGC.TestCommons.csproj +++ b/src/NullGC.TestCommons/NullGC.TestCommons.csproj @@ -14,7 +14,7 @@ - +