-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP] Fix DelegateBodyTests to ensure UseProvidedBody accepts any body #94
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,157 @@ | ||||||||
| using System; | ||||||||
| using System.Linq; | ||||||||
| using System.Text; | ||||||||
| using Microsoft.CodeAnalysis.CSharp.Syntax; | ||||||||
|
|
||||||||
| namespace EasySourceGenerators.Generators.IncrementalGenerators; | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// Extracts the delegate body source code from a <c>UseProvidedBody(...)</c> invocation | ||||||||
| /// within a generator method's syntax tree. The extracted body is re-indented to match | ||||||||
| /// the target method body indentation (8 spaces). | ||||||||
| /// </summary> | ||||||||
| internal static class DelegateBodySyntaxExtractor | ||||||||
| { | ||||||||
| private const string MethodBodyIndent = " "; | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// Attempts to find a <c>UseProvidedBody(...)</c> call in the given generator method syntax | ||||||||
| /// and extract the lambda body. Returns <c>null</c> if no such call is found. | ||||||||
| /// For expression lambdas, returns a single <c>return {expr};</c> line. | ||||||||
|
||||||||
| /// For expression lambdas, returns a single <c>return {expr};</c> line. | |
| /// For expression lambdas, returns the expression text (wrapping into a <c>return {expr};</c> | |
| /// statement is performed later when emitting the method body). |
Copilot
AI
Mar 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExtractBlockBody relies on finding {/} on their own lines via EndsWith("{") / StartsWith("}"). This fails for single-line block lambdas like x => { return 42; }, causing extraction to return null and the generator to fall back to runtime execution (which doesn't preserve arbitrary bodies). Consider extracting the span between block.OpenBraceToken and block.CloseBraceToken (or using tokens/statement list) rather than line-scanning the formatted text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WithCompileTimeConstants(...)is used here, but there is currently no implementation of that method in the concrete fluent builder stages (search shows it exists only in the interface and this example). This will prevent the Examples project/solution from compiling until the builder/runtime support for compile-time constants is added end-to-end.