-
-
Notifications
You must be signed in to change notification settings - Fork 223
Implement the safe_ident
strategy for virtual call parameter identifier generation
#822
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
Conversation
Another solution which would work in this case is generating the identifiers with the escaped identifier syntax, which is how I originally implemented a solution. I figured I'd just use the same solution that already exists in the codegen implementation even though prepending |
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-822 |
Thanks a lot! 🙂 The code duplication isn't great, but I agree it's probably more consistent to stick with the existing approach for now 🤔 could you maybe add a comment in both functions (macro + codegen) to indicate there's duplicated code which would need to be kept in sync? Would it be possible to add a small test that verifies that it compiles? You may need to extend |
6699c6f
to
87cbe77
Compare
Added documentation about the code duplication and what I hope to be a suitable test. I'd rather have implemented more test cases, but I think in this case we can get away with one. My thinking is that the test case is testing whether we call (Sorry about the force pushes, somehow ended up duplicating the squashed commit while attempting to rebase on the latest master and things got far out of hand so very quickly) |
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.
Thanks! Don't worry about force pushes 🙂
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.
Thanks! Once you remove the clippy/rustfmt attributes, change import and squash the commits, should be good to go!
…ter names that might collide with keywords Document duplicated definition of `safe_ident` Add test for `safe_ident` parameter identifier generation for `#[godot-api]` virtual call generation Remove redundant code in keyword parameter test Directly import symbols rather than using prelude
e9985cf
to
b842921
Compare
Thanks a lot! |
The behavior in
maybe_rename_parameter
as currently implemented strips leading underscores from parameter names.The case where
_
is stripped presents a need to sanitize identifiers where we otherwise would not have to, as the removal of the leading underscore may make the identifier match a language keyword. A concrete example someone ran into was an argument namedtype
inIEditorExportPlugin::export_file
in #817.There appears to be an existing approach to keyword-named parameters, as the parameter in the codegen-generated interface is named
type_
. I just implemented that exact strategy in the waymaybe_rename_parameter
generates identifiers after removing a prefixing_
.Codegen Comparison
With the following code from #817
I've included only the changed output from the expanded macro for brevity.
Pre-Change
Specific lines that cause problems:
let(path,type,features,) = params;
instance.export_file(path,type,features)
Post-Change