Robzz / cargo-docset

Cargo subcommand to generate a Dash/Zeal docset for your Rust packages.
Apache License 2.0
100 stars 4 forks source link

Docset index contains relocated symbols that only result in a redirection #34

Closed lilyball closed 2 years ago

lilyball commented 3 years ago

Describe the bug When a crate re-exports symbols from a private module, cargo doc still produces html files for these re-exported symbols in the private module, and these files simply redirect to the public location, and omits the private location from the JS search index. Unfortunately cargo-docset is still indexing these private locations.

To Reproduce

$ cargo init --lib --name doctest
$ cat >src/lib.rs <<EOF
mod foo {
    /// Yes this is Bar.
    pub struct Bar;
}
pub use foo::Bar;
EOF
$ cargo docset
$ sqlite3 target/docset/doctest.docset/Contents/Resources/docSet.dsidx 'SELECT * FROM searchIndex;'
1|doctest|Package|doctest/index.html
2|doctest::Bar|Struct|doctest/struct.Bar.html
3|doctest::foo::Bar|Struct|doctest/foo/struct.Bar.html

Expected behavior The index should look like

1|doctest|Package|doctest/index.html
2|doctest::Bar|Struct|doctest/struct.Bar.html

Screenshots

image

Desktop (please complete the following information):

Additional context These redirection files look like

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="refresh" content="0;URL=../../doctest/struct.Bar.html">
</head>
<body>
    <p>Redirecting to <a href="../../doctest/struct.Bar.html">../../doctest/struct.Bar.html</a>...</p>
    <script>location.replace("../../doctest/struct.Bar.html" + location.search + location.hash);</script>
</body>
</html>

It shouldn't be hard to detect the redirection and ignore the symbol.

I also wonder how hard it would be to extract the JSON search index from target/doc/search-index.js and use that to build the docset index? That seems like a more long-term effort though.

Robzz commented 3 years ago

Thanks for this report and the other ones, I'll look into this and make a new release.

Robzz commented 2 years ago

I finally looked into this and it appears redirection pages now include <title>Redirection</title> in the head section, which is probably the easiest way to identify them. I implemented this in #45 which seems to work and I haven't noticed any missing entries as a consequence. Docset generation does seem a bit slower as a result of reading the beginning of every HTML page, but it's still fast enough that I didn't feel the need to measure it.

I'll make a point release in a few days if I don't notice anything wrong by then.