slint-ui / document-features

Extract documentation for the feature flags from comments in Cargo.toml
Apache License 2.0
171 stars 11 forks source link

Fix parsing of string literal in proc macro argument #14

Closed FedericoStra closed 2 years ago

FedericoStra commented 2 years ago

From the commit message:

Commit 056b0b7d09a4ed49e50182df216361397656425c removed the dependency syn.

In doing so it introduced a bug where the string literal passed to document_features!(feature_label = "...") is not parsed anymore and therefore in the generated Markdown we insert a representation of the string literal as it appears in the source code instead of its content.

For instance, with the call document_features!(feature_label = r#"foo\"#) we insert in the Markdown the text r#"foo\"# instead of foo\.

FedericoStra commented 2 years ago

Sorry to bother you again, but I started using the new code in another project and I realized the custom formatting with feature_label = is broken although the available tests couldn't detect it.

I accidentally introduced the bug when you asked me to remove the syn dependency. With syn I parsed a string literal with literal.value() to access the contents represented by the string. With the change to rely only on proc_macro, I inadvertently removed the parsing of the string literal. This has the effect that in the generated Markdown we now insert the string representation of the literal itself, and not its content.

To work around this I managed to find the litrs crate which can parse string literals and is a much lighter dependency than syn.

Moreover I added some tests that generate the self documentation with various string literals as feature_label in order to check this functionality.

ogoffart commented 2 years ago

thanks