Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update HE 使用 rewriter plugin 重构语法处理部分 #348

Merged
merged 1 commit into from
Jul 7, 2024
Merged

Conversation

NMSAzulX
Copy link
Collaborator

@NMSAzulX NMSAzulX commented Jul 7, 2024

Summary by CodeRabbit

  • New Features

    • Introduced plugin-based architecture for handling method and trivia comments.
    • Added new plugins for async operations, optimization, and debug/release-specific comments.
  • Refactor

    • Renamed several classes and fields for improved clarity and consistency.
    • Restructured HEProxy class to utilize newly introduced plugins.

Copy link

coderabbitai bot commented Jul 7, 2024

Walkthrough

The recent updates focus on enhancing the Natasha.CSharp.HotExecutor component by introducing new classes and plugins for handling method and comment syntax. This plugin-based architecture simplifies method and trivia rewriting, providing a flexible and maintainable approach to manage syntax parsing and code transformation within C# projects.

Changes

File Path (Shortened) Change Summary
.../SyntaxHandler/HEMethodTriviaRewriter.cs Introduced HEMethodTriviaRewriter class for handling method trivia syntax plugins.
.../SyntaxHandler/HETreeMethodRewriter.cs Added HETreeMethodRewriter class for maintaining dictionaries of method plugins and trivia plugins.
.../SyntaxHandler/HETreeTriviaRewriter.cs Introduced HETreeTriviaRewriter class for handling and rewriting single-line comment trivia.
.../SyntaxHandler/OnceHandler.cs Added OnceHandler static class for handling and removing certain comments based on predefined criteria.
.../CS0104TriviaPlugin.cs Introduced CS0104TriviaPlugin class for handling comments related to excluding using directives in C# code.
.../OutputTriviaPlugin.cs Added OutputTriviaPlugin class for handling output comments based on debug or release settings.
.../AsyncTriviaPlugin.cs Introduced AsyncTriviaPlugin class for handling async comments in syntax parsing.
.../OptimizationTriviaPlugin.cs Added OptimizationTriviaPlugin class for handling optimization-related comments and identifying debug or release mode.
.../ProxyMethodPlugin.cs Introduced ProxyMethodPlugin class for handling different project kinds by rewriting blocks of code based on the project type.
.../SyntaxHandler/Standard/MethodSyntaxPluginBase.cs Added abstract class MethodSyntaxPluginBase for handling method syntax.
.../Standard/TriviaSyntaxPluginBase.cs Introduced abstract class TriviaSyntaxPluginBase for handling comment syntax.
.../SyntaxHandler/ToplevelHandler.cs Renamed ToplevelRewriter to ToplevelHandler.
.../SyntaxHandler/UsingsHandler.cs Renamed UsingsRewriter to UsingsHandler and adjusted _defaultUsingNodes initialization.
.../Utils/CommentHelper.cs Added CommentHelper static class with method GetCommentScript for extracting portions of comments.
.../HEProxy.cs Overhauled HEProxy class to use plugins for method proxies, async operations, optimizations, and output comment handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant HEProxy
    participant HETreeMethodRewriter
    participant HETreeTriviaRewriter
    
    User->>HEProxy: Start Hot Compilation
    activate HEProxy
    
    HEProxy->>HETreeMethodRewriter: Register Method Plugins
    activate HETreeMethodRewriter
    HETreeMethodRewriter->>HEProxy: Plugins Registered
    deactivate HETreeMethodRewriter
    
    HEProxy->>HETreeTriviaRewriter: Register Trivia Plugins
    activate HETreeTriviaRewriter
    HETreeTriviaRewriter->>HEProxy: Plugins Registered
    deactivate HETreeTriviaRewriter
    
    HEProxy->>HEProxy: Rewrite Methods and Comments with Plugins
    
    User->>HEProxy: Complete Hot Compilation
    deactivate HEProxy
Loading

Poem

In the realm of code so bright,
Plugins guide with gentle light,
Methods, comments, all in line,
Syntax parsed with grace divine.
Rabbits hop in joy so true,
For clear C# paths, thanks to you.
🎉✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@NMSAzulX
Copy link
Collaborator Author

NMSAzulX commented Jul 7, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Jul 7, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@NMSAzulX
Copy link
Collaborator Author

NMSAzulX commented Jul 7, 2024

未检测到合适的 ISSUE 推荐给您。感谢您的反馈!

该条自动推荐信息来自于 nms-bot.

Copy link

github-actions bot commented Jul 7, 2024

UT Test - Ubuntu

1 tests   1 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 9a3a4c4.

Copy link

github-actions bot commented Jul 7, 2024

UT Test - Windows

1 tests   1 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 9a3a4c4.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Outside diff range and nitpick comments (3)
src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/ToplevelHandler.cs (1)

Line range hint 11-21:
Suggestion: Use StringBuilder for concatenation.

Using StringBuilder for concatenation can improve performance.

- var content = "public class Program{ async static Task Main(string[] args){" + root!.ToFullString() + "}}";
+ var content = new StringBuilder("public class Program{ async static Task Main(string[] args){")
+     .Append(root!.ToFullString())
+     .Append("}}")
+     .ToString();
src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/ProxyMainPlugin/ProxyMethodPlugin.cs (1)

38-41: Add a comment to indicate no initialization needed.

The method is empty and does not perform any initialization. Consider adding a comment to indicate that no initialization is needed.

-  public override void Initialize()
-  {
-    
-  }
+  public override void Initialize()
+  {
+    // No initialization needed
+  }
src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/ProxyMainPlugin/OptimizationTriviaPlugin.cs (1)

25-28: Add a comment to indicate no handling needed.

The method currently does not perform any handling and returns null. Consider adding a comment to indicate that no handling is needed.

-  public override string? Handle(string comment, string lowerComment)
-  {
-    return null;
-  }
+  public override string? Handle(string comment, string lowerComment)
+  {
+    // No handling needed
+    return null;
+  }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 474a9ee and 9a3a4c4.

Files selected for processing (15)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/HEMethodTriviaRewriter.cs (1 hunks)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/HETreeMethodRewriter.cs (1 hunks)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/HETreeTriviaRewriter.cs (1 hunks)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/OnceHandler.cs (1 hunks)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/CS0104Plugin/CS0104TriviaPlugin.cs (1 hunks)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/OutputPlugin/OutputTriviaPlugin.cs (1 hunks)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/ProxyMainPlugin/AsyncTriviaPlugin.cs (1 hunks)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/ProxyMainPlugin/OptimizationTriviaPlugin.cs (1 hunks)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/ProxyMainPlugin/ProxyMethodPlugin.cs (1 hunks)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/Standard/MethodSyntaxPluginBase.cs (1 hunks)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/Standard/TriviaSyntaxPluginBase.cs (1 hunks)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/ToplevelHandler.cs (1 hunks)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/UsingsHandler.cs (1 hunks)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/Utils/CommentHelper.cs (1 hunks)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/HEProxy.cs (13 hunks)
Files skipped from review due to trivial changes (3)
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/Standard/TriviaSyntaxPluginBase.cs
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/UsingsHandler.cs
  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/Utils/CommentHelper.cs
Additional comments not posted (45)
src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/Standard/MethodSyntaxPluginBase.cs (5)

7-8: LGTM! Fields are correctly defined and initialized.

The fields MethodName and TriviaSyntaxPluginBases are appropriately defined and initialized.


9-13: LGTM! Constructor is correctly implemented.

The constructor initializes MethodName and TriviaSyntaxPluginBases correctly.


14-14: LGTM! Abstract method declaration is correct.

The Initialize method is correctly declared as abstract.


16-20: LGTM! Method correctly adds trivia plugin to the list.

The RegisteTriviaPlugin method correctly adds a trivia plugin to the TriviaSyntaxPluginBases list.


21-25: LGTM! Methods are correctly implemented.

The ClearTriviaPlugin method clears the TriviaSyntaxPluginBases list and the Handle method is correctly declared as abstract.

src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/ProxyMainPlugin/AsyncTriviaPlugin.cs (5)

5-6: LGTM! Fields are correctly defined and initialized.

The fields _asyncCommentTag and IsAsync are appropriately defined and initialized.


7-10: LGTM! Constructor is correctly implemented.

The constructor initializes _asyncCommentTag correctly.


11-14: LGTM! Method correctly sets _asyncCommentTag.

The SetAsyncCommentTag method correctly sets _asyncCommentTag.


15-24: LGTM! Methods are correctly implemented.

The Handle method sets IsAsync to true and Initialize resets IsAsync.


26-29: LGTM! Method correctly matches the comment with _asyncCommentTag.

The IsMatch method correctly matches the comment with _asyncCommentTag.

src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/ToplevelHandler.cs (1)

Line range hint 11-21:
LGTM! Method correctly handles top-level statements.

The Handle method correctly handles top-level statements and adds using directives.

src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/CS0104Plugin/CS0104TriviaPlugin.cs (5)

5-6: LGTM! Fields are correctly defined and initialized.

The fields _excludeUsingComment and ExcludeUsings are appropriately defined and initialized.


7-10: LGTM! Constructor is correctly implemented.

The constructor initializes _excludeUsingComment and ExcludeUsings correctly.


13-16: LGTM! Method correctly sets _excludeUsingComment.

The SetMatchComment method correctly sets _excludeUsingComment.


18-21: LGTM! Method correctly clears ExcludeUsings.

The Initialize method correctly clears ExcludeUsings.


23-33: LGTM! Methods are correctly implemented.

The IsMatch method matches the comment with _excludeUsingComment and the Handle method processes the comment.

src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/ProxyMainPlugin/ProxyMethodPlugin.cs (2)

10-13: Constructor looks good!

The constructor correctly initializes the _kind field.


14-17: Method looks good!

The method correctly sets the _kind field.

src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/HEMethodTriviaRewriter.cs (2)

9-12: Constructor looks good!

The constructor correctly initializes the _methodTriviaSyntaxPlugins field.


13-35: Method looks good!

The method correctly processes single-line comments using the registered plugins and returns the modified comment if a plugin handles it.

src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/ProxyMainPlugin/OptimizationTriviaPlugin.cs (4)

8-12: Constructor looks good!

The constructor correctly initializes the _proxyCommentOPLDebug and _proxyCommentOPLRelease fields.


14-17: Method looks good!

The method correctly sets the _proxyCommentOPLDebug field.


19-22: Method looks good!

The method correctly sets the _proxyCommentOPLRelease field.


30-33: Method looks good!

The method correctly initializes the IsRelease field.

src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/HETreeTriviaRewriter.cs (2)

16-19: Constructor looks good!

The constructor correctly initializes the _triviaPlugins field.


27-54: Method looks good!

The method correctly processes single-line comments using the registered plugins and returns the modified comment if a plugin handles it.

src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/SyntaxPlugin/OutputPlugin/OutputTriviaPlugin.cs (6)

9-15: Constructor looks good!

The constructor correctly initializes the properties and sets a unique comment prefix.


17-20: Method looks good!

The method correctly sets the _debugOutputComment property.


22-25: Method looks good!

The method correctly sets the _releaseOutputComment property.


27-34: Method looks good!

The method correctly processes comments based on the release mode.


41-52: Method looks good!

The method correctly checks if a comment matches the debug or release output comment.


54-61: Method looks good!

The method correctly generates a preprocessor replace script.

src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/OnceHandler.cs (3)

10-13: Method looks good!

The method correctly sets the _onceComment property.


14-52: Method looks good!

The method correctly processes compilation unit syntax to remove statements with specific comments.


54-73: Method looks good!

The method correctly checks if a statement should be removed based on its comments.

src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxHandler/HETreeMethodRewriter.cs (1)

49-79: Method looks good!

The method correctly processes method declarations using registered plugins.

src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/HEProxy.cs (9)

42-49: Properties look good!

The properties correctly initialize several plugins and rewriters.


Line range hint 49-71: Static constructor looks good!

The static constructor correctly initializes several fields and registers plugins.


Line range hint 72-109: Method looks good!

The method correctly sets up a project watcher with several callbacks.


Line range hint 110-149: Method looks good!

The method correctly sets up a main watcher with several callbacks.


Line range hint 150-180: Method looks good!

The method correctly initializes and starts the watchers.


Line range hint 181-241: Method looks good!

The method correctly processes a file's syntax tree.


Line range hint 242-343: Method looks good!

The method correctly performs hot execution of the compiled code.


516-516: Method looks good!

The method correctly sets the once comment tag.


540-543: Method looks good!

The method correctly sets the debug output comment tag.

Comment on lines +18 to +35
public override BlockSyntax? Handle(BlockSyntax blockSyntax)
{
ClassDeclarationSyntax? parentClass = blockSyntax.Parent!.Parent as ClassDeclarationSyntax ?? throw new Exception($"获取 {MethodName} 方法类名出现错误!");
ClassName = parentClass.Identifier.Text;

if (_kind == HEProjectKind.Winform)
{
return WinformRewriter.Handle(blockSyntax);
}
else if (_kind == HEProjectKind.WPF)
{
return WpfWriter.Handle(blockSyntax);
}
else if (_kind == HEProjectKind.Console)
{
return ConsoleWriter.Handle(blockSyntax);
}
return null;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a specific exception type.

The method correctly handles different project kinds and rewrites the syntax accordingly. However, consider using a specific exception type for better error handling.

-  ClassDeclarationSyntax? parentClass = blockSyntax.Parent!.Parent as ClassDeclarationSyntax ?? throw new Exception($"获取 {MethodName} 方法类名出现错误!");
+  ClassDeclarationSyntax? parentClass = blockSyntax.Parent!.Parent as ClassDeclarationSyntax ?? throw new InvalidOperationException($"获取 {MethodName} 方法类名出现错误!");
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public override BlockSyntax? Handle(BlockSyntax blockSyntax)
{
ClassDeclarationSyntax? parentClass = blockSyntax.Parent!.Parent as ClassDeclarationSyntax ?? throw new Exception($"获取 {MethodName} 方法类名出现错误!");
ClassName = parentClass.Identifier.Text;
if (_kind == HEProjectKind.Winform)
{
return WinformRewriter.Handle(blockSyntax);
}
else if (_kind == HEProjectKind.WPF)
{
return WpfWriter.Handle(blockSyntax);
}
else if (_kind == HEProjectKind.Console)
{
return ConsoleWriter.Handle(blockSyntax);
}
return null;
public override BlockSyntax? Handle(BlockSyntax blockSyntax)
{
ClassDeclarationSyntax? parentClass = blockSyntax.Parent!.Parent as ClassDeclarationSyntax ?? throw new InvalidOperationException($"获取 {MethodName} 方法类名出现错误!");
ClassName = parentClass.Identifier.Text;
if (_kind == HEProjectKind.Winform)
{
return WinformRewriter.Handle(blockSyntax);
}
else if (_kind == HEProjectKind.WPF)
{
return WpfWriter.Handle(blockSyntax);
}
else if (_kind == HEProjectKind.Console)
{
return ConsoleWriter.Handle(blockSyntax);
}
return null;

Comment on lines +21 to +25
public HETreeTriviaRewriter RegistePlugin(TriviaSyntaxPluginBase triviaSyntaxPluginBase)
{
_triviaPlugins.Add(triviaSyntaxPluginBase);
return this;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename method to RegisterPlugin.

The method correctly adds the plugin to _triviaPlugins but the method name has a spelling error.

-  public HETreeTriviaRewriter RegistePlugin(TriviaSyntaxPluginBase triviaSyntaxPluginBase)
+  public HETreeTriviaRewriter RegisterPlugin(TriviaSyntaxPluginBase triviaSyntaxPluginBase)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public HETreeTriviaRewriter RegistePlugin(TriviaSyntaxPluginBase triviaSyntaxPluginBase)
{
_triviaPlugins.Add(triviaSyntaxPluginBase);
return this;
}
public HETreeTriviaRewriter RegisterPlugin(TriviaSyntaxPluginBase triviaSyntaxPluginBase)
{
_triviaPlugins.Add(triviaSyntaxPluginBase);
return this;
}

Comment on lines +17 to +21
public HETreeMethodRewriter()
{
_methodPlugins = [];
_methodTriviaPlugins = [];
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the initialization of _methodPlugins and _methodTriviaPlugins.

The constructor incorrectly initializes _methodPlugins and _methodTriviaPlugins with empty array brackets instead of new ConcurrentDictionary<>().

-  _methodPlugins = [];
-  _methodTriviaPlugins = [];
+  _methodPlugins = new ConcurrentDictionary<string, HashSet<MethodSyntaxPluginBase>>();
+  _methodTriviaPlugins = new ConcurrentDictionary<string, HashSet<TriviaSyntaxPluginBase>>();
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public HETreeMethodRewriter()
{
_methodPlugins = [];
_methodTriviaPlugins = [];
}
public HETreeMethodRewriter()
{
_methodPlugins = new ConcurrentDictionary<string, HashSet<MethodSyntaxPluginBase>>();
_methodTriviaPlugins = new ConcurrentDictionary<string, HashSet<TriviaSyntaxPluginBase>>();
}

Comment on lines +23 to +47
public HETreeMethodRewriter RegistePlugin(MethodSyntaxPluginBase methodSyntaxPlugin)
{
if (_methodPlugins.TryGetValue(methodSyntaxPlugin.MethodName, out var methodPlugins))
{
methodPlugins.Add(methodSyntaxPlugin);
}
else
{
_methodPlugins[methodSyntaxPlugin.MethodName] = [methodSyntaxPlugin];
}
if (_methodTriviaPlugins.TryGetValue(methodSyntaxPlugin.MethodName, out var triviaPlugins))
{

if (methodSyntaxPlugin.TriviaSyntaxPluginBases.Count>0)
{
triviaPlugins.UnionWith(methodSyntaxPlugin.TriviaSyntaxPluginBases);
}

}
else
{
_methodTriviaPlugins[methodSyntaxPlugin.MethodName] = new(methodSyntaxPlugin.TriviaSyntaxPluginBases);

}
return this;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the use of array brackets for initializing collections.

The method incorrectly uses array brackets for initializing collections instead of new HashSet<>().

-  _methodPlugins[methodSyntaxPlugin.MethodName] = [methodSyntaxPlugin];
-  _methodTriviaPlugins[methodSyntaxPlugin.MethodName] = new(methodSyntaxPlugin.TriviaSyntaxPluginBases);
+  _methodPlugins[methodSyntaxPlugin.MethodName] = new HashSet<MethodSyntaxPluginBase> { methodSyntaxPlugin };
+  _methodTriviaPlugins[methodSyntaxPlugin.MethodName] = new HashSet<TriviaSyntaxPluginBase>(methodSyntaxPlugin.TriviaSyntaxPluginBases);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public HETreeMethodRewriter RegistePlugin(MethodSyntaxPluginBase methodSyntaxPlugin)
{
if (_methodPlugins.TryGetValue(methodSyntaxPlugin.MethodName, out var methodPlugins))
{
methodPlugins.Add(methodSyntaxPlugin);
}
else
{
_methodPlugins[methodSyntaxPlugin.MethodName] = [methodSyntaxPlugin];
}
if (_methodTriviaPlugins.TryGetValue(methodSyntaxPlugin.MethodName, out var triviaPlugins))
{
if (methodSyntaxPlugin.TriviaSyntaxPluginBases.Count>0)
{
triviaPlugins.UnionWith(methodSyntaxPlugin.TriviaSyntaxPluginBases);
}
}
else
{
_methodTriviaPlugins[methodSyntaxPlugin.MethodName] = new(methodSyntaxPlugin.TriviaSyntaxPluginBases);
}
return this;
public HETreeMethodRewriter RegistePlugin(MethodSyntaxPluginBase methodSyntaxPlugin)
{
if (_methodPlugins.TryGetValue(methodSyntaxPlugin.MethodName, out var methodPlugins))
{
methodPlugins.Add(methodSyntaxPlugin);
}
else
{
_methodPlugins[methodSyntaxPlugin.MethodName] = new HashSet<MethodSyntaxPluginBase> { methodSyntaxPlugin };
}
if (_methodTriviaPlugins.TryGetValue(methodSyntaxPlugin.MethodName, out var triviaPlugins))
{
if (methodSyntaxPlugin.TriviaSyntaxPluginBases.Count>0)
{
triviaPlugins.UnionWith(methodSyntaxPlugin.TriviaSyntaxPluginBases);
}
}
else
{
_methodTriviaPlugins[methodSyntaxPlugin.MethodName] = new HashSet<TriviaSyntaxPluginBase>(methodSyntaxPlugin.TriviaSyntaxPluginBases);
}
return this;

@NMSAzulX NMSAzulX merged commit 21bc1bd into dev.next Jul 7, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant