-
Notifications
You must be signed in to change notification settings - Fork 26
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
Fix/program client custom types #117
Conversation
1efa8e4
to
00e1e89
Compare
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.
Lgtm, I would suggest to only optimize the parsing as suggested in the other comment...
crates/client/src/idl.rs
Outdated
} | ||
|
||
fn find_item_path(code: &str, target_item_name: &str) -> Option<String> { | ||
let syn_file = syn::parse_file(code).ok()?; |
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.
I think it is not necessary to call the expensive parse_file function all over again every time the find_item_path is called. It would be better to pass it as a reference to the parsed file that is parsed at the beginning of the parse_to_idl_program
function and therefore do the parsing only once...
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.
I have corrected a problem when a program has a hyphen "-" in its name. This resulted into "unexpected token" error. Converting the name to snake case fixed the issue.
Also, it would be nice to get rid of the unnecessary cloning in the future, but this could be done in a separate PR.
…ypes are private and cannot be used within program_client
a615c4b
to
19a56da
Compare
* obtain full path for custom types (Struct/Enum), provide good UX if types are private and cannot be used within program_client * ✅ add cargo test for program_client * 🔥 removed duplicate code * 🐛 Fixed malformed program name. --------- Co-authored-by: lukacan <[email protected]> Co-authored-by: Ikrk <[email protected]>
* obtain full path for custom types (Struct/Enum), provide good UX if types are private and cannot be used within program_client * ✅ add cargo test for program_client * 🔥 removed duplicate code * 🐛 Fixed malformed program name. --------- Co-authored-by: lukacan <[email protected]> Co-authored-by: Ikrk <[email protected]>
update parse_to_idl_program so that it can obtain the full path for custom types. The implemented function will warn the user if the path is private and cannot be imported.
This is out of scope, but I found it useful to update the examples.
Added some custom types into the cargo test expected/expanded code so that the functionality can be tested.