poliorcetics/cargo-intraconv

Add a way to ignore links

jyn514 opened this issue · 10 comments

Currently, every time I run intraconv, it changes this link:

-    /// [`downcast_ref`]: #method.downcast_ref
+    /// [`downcast_ref`]: Collect::downcast_ref()

That breaks because downcast_ref is a function on dyn Collect, not Collect itself. There's no way for intra-conv to know this, so I don't think it can be fixed on that end, but it would be nice to say "I know this link will break, don't convert it" with a configuration file or something.

Similarly

//! [span]: https://docs.rs/tracing/latest/tracing/span/index.html
//! [span]: tracing::span

gets converted every time, which breaks because tracing isn't in scope in tracing-attributes (rust-lang/rust#74481).

This may become verbose quickly if this is a command line option.

I'm not sure how to do it properly, maybe through a file and a --ignore-links [FILE]

Yeah, a file sounds nice - I was imagining this as configurable per-file and per-link so it would definitely be annoying to type by hand.

What would you want from such a file ? I have no idea about the format I'll use

Edit: What features are you thinking about ?

I was imagining something like this:

[ignore]
[["tracing/src/lib.rs"]]
"`downcast_ref`" = "#method.downcast_ref"

(I checked and that's valid toml.)

Oh nice, if TOML is usable I'll juste use the toml crate and it will be easier (and more solid) than parsing a wonky format.

I'm wondering, would it be more intuitive to use suffixes (mod.rs can match multiple times) or canonicalised paths (mod.rs has been expanded to exactly one file) for the configuration file and the behaviour of intraconv ? What would you expect ?

Maybe it should use .gitignore syntax? Where you can say /tracing/src/mod.rs to mean an absolute path and mod.rs to mean a relative one, possibly matching many files.

Nice idea, I'll go with that !

❯ cg intraconv -i intraconv.toml tracing-core
/Users/alexis/Projects/rust/tracing/tracing-core/src/collect.rs
===============================================================

  443:  "    /// [`downcast_ref`]: #method.downcast_ref"
        "    /// [`downcast_ref`]: Collect::downcast_ref()"

/Users/alexis/Projects/rust/tracing/tracing-core/src/event.rs
=============================================================

   20:  "/// [span]: ../span"
        "/// [span]: super::span"

   21:  "/// [fields]: ../field"
        "/// [fields]: super::field"

/Users/alexis/Projects/rust/tracing/tracing-core/src/lib.rs
===========================================================

   93:  "//! [`libstd`]: https://doc.rust-lang.org/std/index.html"
        "//! [`libstd`]: crate"

  107:  "//! [`liballoc`]: https://doc.rust-lang.org/alloc/index.html"
        "//! [`liballoc`]: alloc"

~/P/r/tracing on  master via  v1.47.0 
❯ cg intraconv tracing-core    
+/Users/alexis/Projects/rust/tracing/tracing-core/src/collect.rs
+===============================================================
+
+  443:  "    /// [`downcast_ref`]: #method.downcast_ref"
+        "    /// [`downcast_ref`]: Collect::downcast_ref()"
+
/Users/alexis/Projects/rust/tracing/tracing-core/src/event.rs
=============================================================

   20:  "/// [span]: ../span"
        "/// [span]: super::span"

   21:  "/// [fields]: ../field"
        "/// [fields]: super::field"

/Users/alexis/Projects/rust/tracing/tracing-core/src/lib.rs
===========================================================

   93:  "//! [`libstd`]: https://doc.rust-lang.org/std/index.html"
        "//! [`libstd`]: crate"

  107:  "//! [`liballoc`]: https://doc.rust-lang.org/alloc/index.html"
        "//! [`liballoc`]: alloc"

With and without the ignore file. I just have to document it properly in the README and I'll push the changes.

   93:  "//! [`libstd`]: https://doc.rust-lang.org/std/index.html"
        "//! [`libstd`]: crate"

Another instance of #32 😓