{"action":"created","comment":{"url":"https://api.github.com/repos/steveklabnik/rustdoc/pulls/comments/128090642","pull_request_review_id":50738372,"id":128090642,"diff_hunk":"@@ -303,3 +191,167 @@ fn generate_analysis(config: &Config) -> Result<(), Box<std::error::Error>> {\n \n     Ok(())\n }\n+\n+#[derive(Debug)]\n+struct DocData {\n+    krate: Crate,\n+    data: HashMap<String, Item>,\n+}\n+\n+impl DocData {\n+    fn new(config: &Config) -> Result<DocData, Box<std::error::Error>> {\n+        let roots = config.host.def_roots()?;\n+\n+        // FIXME: this whole code shouldn't look for a precise crate.\n+        let root_id = roots.iter().find(|&&(_, ref name)| name == \"example\");\n+        let root_id = match root_id {\n+            Some(&(id, _)) => id,\n+            _ => return Err(Box::new(CrateErr::new(\"example\"))),\n+        };\n+\n+        let root_def = config.host.get_def(root_id)?;\n+\n+        let name_len = root_def.qualname.len();\n+        let mut krate = Crate {\n+            id: root_id,\n+            // example:: -> example\n+            name: root_def.qualname[..(name_len - 2)].to_string(),\n+            docs: root_def.docs.clone(),\n+            modules: Vec::new(),\n+        };\n+\n+        let data = DocData::build_data(config, root_id, &mut krate)?;\n+\n+        Ok(DocData { krate, data })\n+    }\n+\n+    fn build_data(\n+        config: &Config,\n+        root_id: analysis::Id,\n+        krate: &mut Crate,\n+    ) -> Result<HashMap<String, Item>, Box<std::error::Error>> {\n+        let mut data = HashMap::new();\n+\n+        let defs = config.host.for_each_child_def(\n+            root_id,\n+            |_, def| def.clone(),\n+        )?;\n+\n+        for def in defs.iter() {\n+            match def.kind {\n+                DefKind::Mod => {\n+                    data.insert(\n+                        def.qualname.clone(),\n+                        Item::Module {\n+                            name: def.name.clone(),\n+                            docs: def.docs.clone(),\n+                        },\n+                    );\n+                    krate.modules.push(def.qualname.clone());\n+                }\n+                DefKind::Static => (),\n+                DefKind::Const => (),\n+                DefKind::Enum => (),\n+                DefKind::Struct => (),\n+                DefKind::Union => (),\n+                DefKind::Trait => (),\n+                DefKind::Function => (),\n+                DefKind::Macro => (),\n+                DefKind::Tuple => (),\n+                DefKind::Method => (),\n+                DefKind::Type => (),\n+                DefKind::Local => (),\n+                DefKind::Field => (),\n+            }\n+        }\n+\n+        Ok(data)\n+    }\n+\n+    fn to_json(&self, config: &Config) -> Result<String, Box<std::error::Error>> {\n+        use jsonapi::api::*;\n+\n+        let root_def = config.host.get_def(self.krate.id)?;\n+\n+        let mut document = JsonApiDocument::default();\n+\n+        let mut map = HashMap::new();\n+        map.insert(\n+            String::from(\"docs\"),\n+            serde_json::Value::String(root_def.docs.clone()),\n+        );\n+\n+        let mut relationships = HashMap::new();\n+\n+        let mut relationship = Relationship {\n+            data: IdentifierData::Multiple(Vec::new()),\n+            links: None,\n+        };\n+\n+        //TODO this is bad, use real option handling in the loop\n+        document.included = Some(Vec::new());\n+\n+        for (id, item) in self.data.iter() {\n+            match item {\n+                &Item::Module { ref name, ref docs } => {\n+                    if let IdentifierData::Multiple(ref mut v) = relationship.data {\n+                        v.push(ResourceIdentifier {\n+                            _type: String::from(\"module\"),\n+                            id: id.clone(),\n+                        });\n+                    };\n+                    let mut map = HashMap::new();\n+                    map.insert(\n+                        String::from(\"name\"),\n+                        serde_json::Value::String(name.clone()),\n+                    );\n+                    map.insert(\n+                        String::from(\"docs\"),\n+                        serde_json::Value::String(docs.clone()),\n+                    );\n+\n+                    let module = Resource {\n+                        _type: String::from(\"module\"),\n+                        id: id.clone(),\n+                        attributes: map,\n+                        links: None,\n+                        meta: None,\n+                        relationships: None,\n+                    };\n+\n+                    document.included.as_mut().map(|v| v.push(module));\n+                }\n+            }\n+        }\n+\n+        relationships.insert(String::from(\"modules\"), relationship);\n+\n+        let len = root_def.qualname.len();\n+        let krate = Resource {\n+            _type: String::from(\"crate\"),\n+            // example:: -> example\n+            id: root_def.qualname[..(len - 2)].to_string(),\n+            attributes: map,\n+            links: None,\n+            meta: None,\n+            relationships: Some(relationships),\n+        };\n+\n+        document.data = Some(PrimaryData::Single(Box::new(krate)));\n+\n+        serde_json::to_string(&document).map_err(|e| Box::new(e) as Box<std::error::Error>)\n+    }\n+}\n+\n+#[derive(Debug)]\n+struct Crate {\n+    id: analysis::Id,\n+    name: String,\n+    docs: String,\n+    modules: Vec<String>,\n+}\n+\n+#[derive(Debug)]\n+enum Item {\n+    Module { name: String, docs: String },","path":"src/lib.rs","position":324,"original_position":324,"commit_id":"fdcec710cdff6eeed56968761ea82c1f3469adbd","original_commit_id":"fdcec710cdff6eeed56968761ea82c1f3469adbd","user":{"login":"mgattozzi","id":3514399,"avatar_url":"https://avatars3.githubusercontent.com/u/3514399?v=4","gravatar_id":"","url":"https://api.github.com/users/mgattozzi","html_url":"https://github.com/mgattozzi","followers_url":"https://api.github.com/users/mgattozzi/followers","following_url":"https://api.github.com/users/mgattozzi/following{/other_user}","gists_url":"https://api.github.com/users/mgattozzi/gists{/gist_id}","starred_url":"https://api.github.com/users/mgattozzi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgattozzi/subscriptions","organizations_url":"https://api.github.com/users/mgattozzi/orgs","repos_url":"https://api.github.com/users/mgattozzi/repos","events_url":"https://api.github.com/users/mgattozzi/events{/privacy}","received_events_url":"https://api.github.com/users/mgattozzi/received_events","type":"User","site_admin":false},"body":"This will be expanded over time I'm guessing based off the `DefKind` matching block above right?","created_at":"2017-07-18T20:46:33Z","updated_at":"2017-07-18T20:46:33Z","html_url":"https://github.com/steveklabnik/rustdoc/pull/47#discussion_r128090642","pull_request_url":"https://api.github.com/repos/steveklabnik/rustdoc/pulls/47","_links":{"self":{"href":"https://api.github.com/repos/steveklabnik/rustdoc/pulls/comments/128090642"},"html":{"href":"https://github.com/steveklabnik/rustdoc/pull/47#discussion_r128090642"},"pull_request":{"href":"https://api.github.com/repos/steveklabnik/rustdoc/pulls/47"}}},"pull_request":{"url":"https://api.github.com/repos/steveklabnik/rustdoc/pulls/47","id":131180238,"html_url":"https://github.com/steveklabnik/rustdoc/pull/47","diff_url":"https://github.com/steveklabnik/rustdoc/pull/47.diff","patch_url":"https://github.com/steveklabnik/rustdoc/pull/47.patch","issue_url":"https://api.github.com/repos/steveklabnik/rustdoc/issues/47","number":47,"state":"open","locked":false,"title":"Refactor flow of the backend","user":{"login":"steveklabnik","id":27786,"avatar_url":"https://avatars2.githubusercontent.com/u/27786?v=4","gravatar_id":"","url":"https://api.github.com/users/steveklabnik","html_url":"https://github.com/steveklabnik","followers_url":"https://api.github.com/users/steveklabnik/followers","following_url":"https://api.github.com/users/steveklabnik/following{/other_user}","gists_url":"https://api.github.com/users/steveklabnik/gists{/gist_id}","starred_url":"https://api.github.com/users/steveklabnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steveklabnik/subscriptions","organizations_url":"https://api.github.com/users/steveklabnik/orgs","repos_url":"https://api.github.com/users/steveklabnik/repos","events_url":"https://api.github.com/users/steveklabnik/events{/privacy}","received_events_url":"https://api.github.com/users/steveklabnik/received_events","type":"User","site_admin":false},"body":"This ends up removing generate_json into better parts, and refactors\r\nbuild to use those parts properly.\r\n\r\nThe new DocData struct reifies the previous 'data' hash that was in\r\ngenerate_json, and gives it some structure.\r\n\r\nDocData::to_json is still messy and won't work for arbitrary stuff\r\nyet; that's the next big work to do!\r\n\r\nI should note that originally, I conceived of `DocData` as an AST of sorts, but the problem with that is that for it all to be valid, you have to bring the entire tree up to build it. As such, the HashMap with linked IDs approach means that we don't have to; we can create the bits before they're done. This is important for really large docs trees, as we don't want to store literally everything in memory at all times, and also paves the way for things like streaming output.\r\n\r\nGiven that the `JsonAPI` crate ends up needing to build the entire tree, and it's painful, we might need to switch away from it in the future, dunno.\r\n\r\nFixes #11","created_at":"2017-07-18T20:32:37Z","updated_at":"2017-07-18T20:46:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c03ebd48fb02fbb645e78d9093dedeed443cfb2b","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/steveklabnik/rustdoc/pulls/47/commits","review_comments_url":"https://api.github.com/repos/steveklabnik/rustdoc/pulls/47/comments","review_comment_url":"https://api.github.com/repos/steveklabnik/rustdoc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/steveklabnik/rustdoc/issues/47/comments","statuses_url":"https://api.github.com/repos/steveklabnik/rustdoc/statuses/fdcec710cdff6eeed56968761ea82c1f3469adbd","head":{"label":"steveklabnik:gh11","ref":"gh11","sha":"fdcec710cdff6eeed56968761ea82c1f3469adbd","user":{"login":"steveklabnik","id":27786,"avatar_url":"https://avatars2.githubusercontent.com/u/27786?v=4","gravatar_id":"","url":"https://api.github.com/users/steveklabnik","html_url":"https://github.com/steveklabnik","followers_url":"https://api.github.com/users/steveklabnik/followers","following_url":"https://api.github.com/users/steveklabnik/following{/other_user}","gists_url":"https://api.github.com/users/steveklabnik/gists{/gist_id}","starred_url":"https://api.github.com/users/steveklabnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steveklabnik/subscriptions","organizations_url":"https://api.github.com/users/steveklabnik/orgs","repos_url":"https://api.github.com/users/steveklabnik/repos","events_url":"https://api.github.com/users/steveklabnik/events{/privacy}","received_events_url":"https://api.github.com/users/steveklabnik/received_events","type":"User","site_admin":false},"repo":{"id":91756901,"name":"rustdoc","full_name":"steveklabnik/rustdoc","owner":{"login":"steveklabnik","id":27786,"avatar_url":"https://avatars2.githubusercontent.com/u/27786?v=4","gravatar_id":"","url":"https://api.github.com/users/steveklabnik","html_url":"https://github.com/steveklabnik","followers_url":"https://api.github.com/users/steveklabnik/followers","following_url":"https://api.github.com/users/steveklabnik/following{/other_user}","gists_url":"https://api.github.com/users/steveklabnik/gists{/gist_id}","starred_url":"https://api.github.com/users/steveklabnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steveklabnik/subscriptions","organizations_url":"https://api.github.com/users/steveklabnik/orgs","repos_url":"https://api.github.com/users/steveklabnik/repos","events_url":"https://api.github.com/users/steveklabnik/events{/privacy}","received_events_url":"https://api.github.com/users/steveklabnik/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/steveklabnik/rustdoc","description":"A documentation tool for Rust.","fork":false,"url":"https://api.github.com/repos/steveklabnik/rustdoc","forks_url":"https://api.github.com/repos/steveklabnik/rustdoc/forks","keys_url":"https://api.github.com/repos/steveklabnik/rustdoc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/steveklabnik/rustdoc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/steveklabnik/rustdoc/teams","hooks_url":"https://api.github.com/repos/steveklabnik/rustdoc/hooks","issue_events_url":"https://api.github.com/repos/steveklabnik/rustdoc/issues/events{/number}","events_url":"https://api.github.com/repos/steveklabnik/rustdoc/events","assignees_url":"https://api.github.com/repos/steveklabnik/rustdoc/assignees{/user}","branches_url":"https://api.github.com/repos/steveklabnik/rustdoc/branches{/branch}","tags_url":"https://api.github.com/repos/steveklabnik/rustdoc/tags","blobs_url":"https://api.github.com/repos/steveklabnik/rustdoc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/steveklabnik/rustdoc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/steveklabnik/rustdoc/git/refs{/sha}","trees_url":"https://api.github.com/repos/steveklabnik/rustdoc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/steveklabnik/rustdoc/statuses/{sha}","languages_url":"https://api.github.com/repos/steveklabnik/rustdoc/languages","stargazers_url":"https://api.github.com/repos/steveklabnik/rustdoc/stargazers","contributors_url":"https://api.github.com/repos/steveklabnik/rustdoc/contributors","subscribers_url":"https://api.github.com/repos/steveklabnik/rustdoc/subscribers","subscription_url":"https://api.github.com/repos/steveklabnik/rustdoc/subscription","commits_url":"https://api.github.com/repos/steveklabnik/rustdoc/commits{/sha}","git_commits_url":"https://api.github.com/repos/steveklabnik/rustdoc/git/commits{/sha}","comments_url":"https://api.github.com/repos/steveklabnik/rustdoc/comments{/number}","issue_comment_url":"https://api.github.com/repos/steveklabnik/rustdoc/issues/comments{/number}","contents_url":"https://api.github.com/repos/steveklabnik/rustdoc/contents/{+path}","compare_url":"https://api.github.com/repos/steveklabnik/rustdoc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/steveklabnik/rustdoc/merges","archive_url":"https://api.github.com/repos/steveklabnik/rustdoc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/steveklabnik/rustdoc/downloads","issues_url":"https://api.github.com/repos/steveklabnik/rustdoc/issues{/number}","pulls_url":"https://api.github.com/repos/steveklabnik/rustdoc/pulls{/number}","milestones_url":"https://api.github.com/repos/steveklabnik/rustdoc/milestones{/number}","notifications_url":"https://api.github.com/repos/steveklabnik/rustdoc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/steveklabnik/rustdoc/labels{/name}","releases_url":"https://api.github.com/repos/steveklabnik/rustdoc/releases{/id}","deployments_url":"https://api.github.com/repos/steveklabnik/rustdoc/deployments","created_at":"2017-05-19T02:26:47Z","updated_at":"2017-07-18T04:41:05Z","pushed_at":"2017-07-18T20:32:37Z","git_url":"git://github.com/steveklabnik/rustdoc.git","ssh_url":"git@github.com:steveklabnik/rustdoc.git","clone_url":"https://github.com/steveklabnik/rustdoc.git","svn_url":"https://github.com/steveklabnik/rustdoc","homepage":"","size":502,"stargazers_count":50,"watchers_count":50,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":20,"mirror_url":null,"open_issues_count":19,"forks":20,"open_issues":19,"watchers":50,"default_branch":"master"}},"base":{"label":"steveklabnik:master","ref":"master","sha":"03aaf0c3224c01117aa4bd1a088583921066ce97","user":{"login":"steveklabnik","id":27786,"avatar_url":"https://avatars2.githubusercontent.com/u/27786?v=4","gravatar_id":"","url":"https://api.github.com/users/steveklabnik","html_url":"https://github.com/steveklabnik","followers_url":"https://api.github.com/users/steveklabnik/followers","following_url":"https://api.github.com/users/steveklabnik/following{/other_user}","gists_url":"https://api.github.com/users/steveklabnik/gists{/gist_id}","starred_url":"https://api.github.com/users/steveklabnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steveklabnik/subscriptions","organizations_url":"https://api.github.com/users/steveklabnik/orgs","repos_url":"https://api.github.com/users/steveklabnik/repos","events_url":"https://api.github.com/users/steveklabnik/events{/privacy}","received_events_url":"https://api.github.com/users/steveklabnik/received_events","type":"User","site_admin":false},"repo":{"id":91756901,"name":"rustdoc","full_name":"steveklabnik/rustdoc","owner":{"login":"steveklabnik","id":27786,"avatar_url":"https://avatars2.githubusercontent.com/u/27786?v=4","gravatar_id":"","url":"https://api.github.com/users/steveklabnik","html_url":"https://github.com/steveklabnik","followers_url":"https://api.github.com/users/steveklabnik/followers","following_url":"https://api.github.com/users/steveklabnik/following{/other_user}","gists_url":"https://api.github.com/users/steveklabnik/gists{/gist_id}","starred_url":"https://api.github.com/users/steveklabnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steveklabnik/subscriptions","organizations_url":"https://api.github.com/users/steveklabnik/orgs","repos_url":"https://api.github.com/users/steveklabnik/repos","events_url":"https://api.github.com/users/steveklabnik/events{/privacy}","received_events_url":"https://api.github.com/users/steveklabnik/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/steveklabnik/rustdoc","description":"A documentation tool for Rust.","fork":false,"url":"https://api.github.com/repos/steveklabnik/rustdoc","forks_url":"https://api.github.com/repos/steveklabnik/rustdoc/forks","keys_url":"https://api.github.com/repos/steveklabnik/rustdoc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/steveklabnik/rustdoc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/steveklabnik/rustdoc/teams","hooks_url":"https://api.github.com/repos/steveklabnik/rustdoc/hooks","issue_events_url":"https://api.github.com/repos/steveklabnik/rustdoc/issues/events{/number}","events_url":"https://api.github.com/repos/steveklabnik/rustdoc/events","assignees_url":"https://api.github.com/repos/steveklabnik/rustdoc/assignees{/user}","branches_url":"https://api.github.com/repos/steveklabnik/rustdoc/branches{/branch}","tags_url":"https://api.github.com/repos/steveklabnik/rustdoc/tags","blobs_url":"https://api.github.com/repos/steveklabnik/rustdoc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/steveklabnik/rustdoc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/steveklabnik/rustdoc/git/refs{/sha}","trees_url":"https://api.github.com/repos/steveklabnik/rustdoc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/steveklabnik/rustdoc/statuses/{sha}","languages_url":"https://api.github.com/repos/steveklabnik/rustdoc/languages","stargazers_url":"https://api.github.com/repos/steveklabnik/rustdoc/stargazers","contributors_url":"https://api.github.com/repos/steveklabnik/rustdoc/contributors","subscribers_url":"https://api.github.com/repos/steveklabnik/rustdoc/subscribers","subscription_url":"https://api.github.com/repos/steveklabnik/rustdoc/subscription","commits_url":"https://api.github.com/repos/steveklabnik/rustdoc/commits{/sha}","git_commits_url":"https://api.github.com/repos/steveklabnik/rustdoc/git/commits{/sha}","comments_url":"https://api.github.com/repos/steveklabnik/rustdoc/comments{/number}","issue_comment_url":"https://api.github.com/repos/steveklabnik/rustdoc/issues/comments{/number}","contents_url":"https://api.github.com/repos/steveklabnik/rustdoc/contents/{+path}","compare_url":"https://api.github.com/repos/steveklabnik/rustdoc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/steveklabnik/rustdoc/merges","archive_url":"https://api.github.com/repos/steveklabnik/rustdoc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/steveklabnik/rustdoc/downloads","issues_url":"https://api.github.com/repos/steveklabnik/rustdoc/issues{/number}","pulls_url":"https://api.github.com/repos/steveklabnik/rustdoc/pulls{/number}","milestones_url":"https://api.github.com/repos/steveklabnik/rustdoc/milestones{/number}","notifications_url":"https://api.github.com/repos/steveklabnik/rustdoc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/steveklabnik/rustdoc/labels{/name}","releases_url":"https://api.github.com/repos/steveklabnik/rustdoc/releases{/id}","deployments_url":"https://api.github.com/repos/steveklabnik/rustdoc/deployments","created_at":"2017-05-19T02:26:47Z","updated_at":"2017-07-18T04:41:05Z","pushed_at":"2017-07-18T20:32:37Z","git_url":"git://github.com/steveklabnik/rustdoc.git","ssh_url":"git@github.com:steveklabnik/rustdoc.git","clone_url":"https://github.com/steveklabnik/rustdoc.git","svn_url":"https://github.com/steveklabnik/rustdoc","homepage":"","size":502,"stargazers_count":50,"watchers_count":50,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":20,"mirror_url":null,"open_issues_count":19,"forks":20,"open_issues":19,"watchers":50,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/steveklabnik/rustdoc/pulls/47"},"html":{"href":"https://github.com/steveklabnik/rustdoc/pull/47"},"issue":{"href":"https://api.github.com/repos/steveklabnik/rustdoc/issues/47"},"comments":{"href":"https://api.github.com/repos/steveklabnik/rustdoc/issues/47/comments"},"review_comments":{"href":"https://api.github.com/repos/steveklabnik/rustdoc/pulls/47/comments"},"review_comment":{"href":"https://api.github.com/repos/steveklabnik/rustdoc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/steveklabnik/rustdoc/pulls/47/commits"},"statuses":{"href":"https://api.github.com/repos/steveklabnik/rustdoc/statuses/fdcec710cdff6eeed56968761ea82c1f3469adbd"}}}}
{"actor":{"display_login":"mgattozzi"}}