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 HEProxy.cs #331

Merged
merged 1 commit into from
Jun 29, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ static HEProxy()
_debugOptions = new CSharpParseOptions(LanguageVersion.Preview, preprocessorSymbols: ["DEBUG"]);
_currentOptions = _debugOptions;
_releaseOptions = new CSharpParseOptions(LanguageVersion.Preview, preprocessorSymbols: ["RELEASE"]);

#if DEBUG
if (Console.Out is not StreamWriter)
{
ShowMessage = msg => { Debug.WriteLine(msg); };
}
#endif
_buildLock = new();
_mainWatcher = new();
_processor = new();
Expand Down Expand Up @@ -186,7 +179,6 @@ public static void Run()
#endif

}

private static SyntaxTree? HandleTree(string file)
{
var tree = NatashaCSharpSyntax.ParseTree(ReadUtf8File(file), file, _currentOptions, Encoding.UTF8);
Expand Down Expand Up @@ -220,6 +212,7 @@ public static void Run()
Debug.WriteLine(root.ToFullString());
return GetOptimizationLevelNode(file, root, Encoding.UTF8);
}

Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Ensure all calls to SetProjectKind are updated accordingly.

The method body has been removed, but calls to SetProjectKind still exist in HotExecutorGenerator.cs. This will lead to runtime errors if these calls are executed. Please update or remove these calls.

  • src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor.SG/HotExecutorGenerator.cs
Analysis chain

Verify all function calls to SetProjectKind are updated accordingly.

The method body has been removed. Ensure that all calls to SetProjectKind are updated accordingly.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all function calls to `SetProjectKind` are updated accordingly.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type cs 'SetProjectKind'

Length of output: 623



Script:

#!/bin/bash
# Description: Extract lines around the calls to `SetProjectKind` in HotExecutorGenerator.cs
rg --type cs --context 5 'SetProjectKind' src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor.SG/HotExecutorGenerator.cs

Length of output: 1456

private static HEProjectKind _projectKind;
public static void SetProjectKind(HEProjectKind kind)
{
Expand All @@ -240,7 +233,7 @@ private static async Task HotExecute()
_currentOptions = _debugOptions;
ReAnalysisFiles();
}
if (Console.Out is StreamWriter)
if (_projectKind == HEProjectKind.Console || _projectKind == HEProjectKind.AspnetCore)
{
Console.Clear();
}
Expand Down Expand Up @@ -350,6 +343,7 @@ private static async Task HotExecute()
}
return;
}

#region 辅助方法区
public static void SetDefaultUsingCode(UsingDirectiveSyntax[] usings)
{
Expand Down Expand Up @@ -485,7 +479,7 @@ private static CompilationUnitSyntax HandleToplevelNodes(string file, Compilatio
ShowMessage("检测到顶级语句!");
#endif
var usings = root.Usings;
root = root.RemoveNodes(usings, SyntaxRemoveOptions.KeepLeadingTrivia)!;
root = root.RemoveNodes(usings, SyntaxRemoveOptions.KeepExteriorTrivia)!;
var content = "public class Program{ async static Task Main(string[] args){" + root!.ToFullString() + "}}";
var tree = NatashaCSharpSyntax.ParseTree(content, file, _currentOptions);
root = tree.GetCompilationUnitRoot();
Expand Down Expand Up @@ -758,7 +752,11 @@ void HandleTriviaComment(SyntaxTriviaList trivias, int i, bool needDeleted)

private static StatementSyntax CreatePreprocessorConsoleWriteLineSyntaxNode(string content)
{
return SyntaxFactory.ParseStatement($"HEProxy.ShowMessage({content});");
if (_projectKind == HEProjectKind.AspnetCore || _projectKind == HEProjectKind.Console)
{
return SyntaxFactory.ParseStatement($"Console.WriteLine({content});");
}
return SyntaxFactory.ParseStatement($"HEProxy.ShowMessage(({content}).ToString());");
}
private static CompilationUnitSyntax HandlePickedProxyMethod(CompilationUnitSyntax root)
{
Expand Down Expand Up @@ -843,6 +841,17 @@ private static CompilationUnitSyntax HandlePickedProxyMethod(CompilationUnitSynt
}});
}});")]);
}
else if (_projectKind == HEProjectKind.Console)
{
if (blockSyntax.Statements.Count>0)
{
var node = blockSyntax.Statements.Last();
if (node.ToString() =="Console.ReadKey();")
{
return blockSyntax.RemoveNode(node, SyntaxRemoveOptions.KeepExteriorTrivia);
}
}
}
return null;
}
private static void HandleOptimizationLevel(MethodDeclarationSyntax methodNode)
Expand Down
Loading