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

Consider using a better way to parse source code for migration generator #67

Open
m4tx opened this issue Nov 12, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@m4tx
Copy link
Contributor

m4tx commented Nov 12, 2024

Currently the migration generator is somewhat hacky in the sense that it parses raw Rust source files and ignores things like macros, some weirder syntaxes, etc. use statements are parsed, but not perfectly, which might result in generating migrations that need manual changes to compile. What might be the worst is that it cannot access any actual type/constant data, so the migrations must include stuff like below:

.set_null(
    <crate::db::LimitedString<
        { crate::auth::db::MAX_USERNAME_LENGTH },
    > as ::flareon::db::DatabaseField>::NULLABLE,
)

(which is equivalent to .set_null(false) at compile time).

I would be ideal to use something closer to the the actual Rust compiler to parse models in the CLI, so we have access to full data about the types used in the project.

Some options that are worth considering:

  • rust-analyzer - basically a Rust compiler with a nice API. LSP protocol might be somewhat cumbersome to get what we need, but it's possible we should be able to get the data we want.
  • cargo +nightly rustdoc -- -Z unstable-options --output-format json - generates a JSON file which annotates fields in the structures with the actual types they use. Might be useful, but it doesn't seem to resolve constant or associated types, so its usefulness is probably somewhat limited (more investigation might be needed).
  • It might be worth looking at how evcxr does things under the hood
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant