steveklabnik / rustdoc

Not a real thing, see https://github.com/rust-lang/rust for rustdoc's actual source code
https://github.com/rust-lang/rust
104 stars 22 forks source link

Modules: parent links #210

Closed steveklabnik closed 6 years ago

steveklabnik commented 6 years ago

We're gonna need to modify the JSON slightly to add parent links for modules. In theory, libraries could figure out that this is true, but in reality, they don't, and so this gives them a bit less work to do.

I have a failing test here, but am not likely to get it passing until tomorrow. If anyone wants to take a shot at this in the meantime, it would be very helpful!

steveklabnik commented 6 years ago

Ah, looks like this is actually pretty easy...

steveklabnik commented 6 years ago

This should pass the above test, but the negative test I referred to above will fail:

  "relationships": {
        "structs": {
          "data": [
            {
              "type": "struct",
              "id": "example::example_module::AnotherStruct"
            }
          ]
        },
        "parent": {
          "data": [
            {
              "type": "module",
              "id": "example::"
            }
          ]
        }

this makes sense, as modules at the root do have the anonymous root module as their parent.

steveklabnik commented 6 years ago

I've fixed the bug, but still don't know how to write the test. Let's not merge till we have that so that we don't regress.

steveklabnik commented 6 years ago

Okay, so this is also slightly off: parent shouldn't be an array, just an object.

Looks like we currently assume all relationships will be a list... gah. Not gonna get to that until tomorrow.

steveklabnik commented 6 years ago

Looks like https://docs.rs/jsonapi/0.5.2/jsonapi/api/enum.IdentifierData.html will basically be how we need to change relationships; an enum of vec or hashmap.

steveklabnik commented 6 years ago

i pushed the refactoring alone as https://github.com/steveklabnik/rustdoc/pull/210/commits/062a8b70b913f714429944c93afd992b3ba91e99 so it's easy to verify that the test changes i made are good

steveklabnik commented 6 years ago

Hm, I expected this test to now pass, because it's generating it correctly: (this is for the example crate)

    {
      "type": "module",
      "id": "example::nested1::nested2",
      "attributes": {
        "name": "nested2",
        "docs": " nested 2\n"
      },
      "relationships": {
        "parent": {
          "data": {
            "type": "module",
            "id": "example::nested1"
          }
        },
        "modules": {
          "data": [
            {
              "type": "module",
              "id": "example::nested1::nested2::nested3"
            }
          ]
        }
      }

more investigation needed but we're close!

steveklabnik commented 6 years ago
        error: test failed on line 29
caused by: test failed on line 29
backtrace, if any:
thread 'docs::nested_modules' panicked at 'explicit panic', C:\Users\steve\src\rustdoc\target\debug\build\rustdoc-b0104c9e001a8e5b\out/source_generated.rs:1:3750
note: Run with `RUST_BACKTRACE=1` for a backtrace.

but

   {
      "type": "module",
      "id": "example::example_module::nested",
      "attributes": {
        "name": "nested",
        "docs": ""
      },
      "relationships": {
        "parent": {
          "data": {
            "type": "module",
            "id": "example::example_module"
          }
        },
        "modules": {
          "data": [
            {
              "type": "module",
              "id": "example::example_module::nested::nested2"
            }
          ]
        }
      }
    },

.... do I have the test syntax wrong or something?

steveklabnik commented 6 years ago

Yup, I broke the tests when I "fixed" them. Sigh.

This should now pass!

steveklabnik commented 6 years ago

apparently the os x builders are.... acting strange