Skip to content

Conversation

@nyurik
Copy link
Member

@nyurik nyurik commented Jan 25, 2026

Instead of a comment at the top, generate usable constants:

pub const DBC_FILE_NAME: &str = "filename";
pub const DBC_FILE_VERSION: &str = "1.0";

Use token parser and prettyplease code formatter to generate stable code output. This also allows us to migrate to syn/quote-based code generation in the future, rather than rely on text manipulation.

Note that this re-generates all expected code files, but the changes are minor - mostly a few newlines, minor formatting, and the two new constants from above.

Instead of a comment at the top, generate usable constants:

```rust
pub const DBC_FILE_NAME: &str = "filename";
pub const DBC_FILE_VERSION: &str = "1.0";
```

Use token parser and `prettyplease` code formatter to generate
stable code output.  This also allows us to migrate to syn/quote-based
code generation in the future, rather than rely on text manipulation.
@nyurik nyurik requested review from Copilot, tegimeki and trnila January 25, 2026 23:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR replaces the comment-based file metadata header with usable constants and implements proper code formatting using prettyplease and syn for stable output generation.

Changes:

  • Replaced top-of-file comments with DBC_FILE_NAME and DBC_FILE_VERSION constants
  • Integrated prettyplease for consistent code formatting
  • Added syn and prettyplease dependencies to enable token-based parsing and formatting

Reviewed changes

Copilot reviewed 53 out of 98 changed files in this pull request and generated no comments.

File Description
src/lib.rs Replaced comment generation with constant declarations; integrated prettyplease formatting in generate() and write() methods
Cargo.toml Added prettyplease and syn dependencies for code formatting
tests-snapshots/dbc-cantools/*.snap.rs Updated snapshot files showing formatted output with new constants replacing comments
tests-snapshots/dbc-cantools/*.snap.stderr Updated error snapshots reflecting new line numbers after formatting changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Jan 25, 2026

Codecov Report

❌ Patch coverage is 57.14286% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/lib.rs 57.14% 2 Missing and 7 partials ⚠️

📢 Thoughts on this report? Let us know!

src/lib.rs Outdated
})?;

writeln!(w)?;
let dbc_name = config.dbc_name.escape_default();
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of putting these at the top of the file, before the other imports, with a comment indicating "/// Code generated from DBC file"? Then the future #[doc] usage via quote will still be do-able (it will comment the filename string) and the message appears where it used to, as a warning to someone who might attempt to modify it.

@nyurik nyurik merged commit 36b4514 into oxibus:main Jan 26, 2026
7 checks passed
@nyurik nyurik deleted the pretty-print branch January 26, 2026 16:59
@nyurik nyurik mentioned this pull request Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants