Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(html): property drilldown #529

Merged
merged 14 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 34 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ tree-sitter-css = { version = "0.20.0", optional = true }
tree-sitter-toml = { version = "0.20.0", optional = true }
tree-sitter-md = { version = "0.1.7", optional = true }
tree-sitter-rust = { version = "0.20.4", optional = true }
tree-sitter-html = { version = "0.20.0", optional = true }
tree-sitter-bash = { version = "0.20.5", optional = true }

[dev-dependencies]
anyhow = { version = "1.0.58" }
Expand All @@ -82,6 +84,8 @@ tree-sitter = [
"tree-sitter-toml",
"tree-sitter-md",
"tree-sitter-rust",
"tree-sitter-html",
"tree-sitter-bash",
]

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion examples/ddoc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async fn run() -> anyhow::Result<()> {
let mut doc_nodes = Vec::with_capacity(1024);
for source_file in source_files {
let nodes = parser.parse_with_reexports(&source_file)?;
doc_nodes.extend_from_slice(&nodes);
doc_nodes.extend(nodes);
}

doc_nodes.retain(|doc_node| doc_node.kind != DocNodeKind::Import);
Expand Down
4 changes: 3 additions & 1 deletion src/display.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use crate::colors;
use std::fmt::{Display, Formatter, Result};
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result;

pub(crate) struct Indent(pub i64);

Expand Down
94 changes: 66 additions & 28 deletions src/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod types;
mod usage;
mod util;

pub use pages::generate_symbol_page;
use crate::html::pages::SymbolPage;
pub use pages::generate_symbol_pages_for_module;
pub use render_context::RenderContext;
pub use search::generate_search_index;
Expand Down Expand Up @@ -142,6 +142,7 @@ impl<'ctx> GenerateCtx<'ctx> {
.map(|node| DocNodeWithContext {
origin: Rc::new(self.url_to_short_path(specifier)),
ns_qualifiers: Rc::new(vec![]),
kind_with_drilldown: DocNodeKindWithDrilldown::Other(node.kind),
inner: Rc::new(node.clone()),
})
.collect::<Vec<_>>(),
Expand Down Expand Up @@ -180,13 +181,21 @@ impl From<String> for ShortPath {
}
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
pub enum DocNodeKindWithDrilldown {
Property,
Method,
Other(crate::DocNodeKind),
}

/// A wrapper around [`DocNode`] with additional fields to track information
/// about the inner [`DocNode`].
/// This is cheap to clone since all fields are [`Rc`]s.
#[derive(Clone, Debug)]
pub struct DocNodeWithContext {
pub origin: Rc<ShortPath>,
pub ns_qualifiers: Rc<Vec<String>>,
pub kind_with_drilldown: DocNodeKindWithDrilldown,
pub inner: Rc<DocNode>,
}

Expand All @@ -195,6 +204,7 @@ impl DocNodeWithContext {
DocNodeWithContext {
origin: self.origin.clone(),
ns_qualifiers: self.ns_qualifiers.clone(),
kind_with_drilldown: DocNodeKindWithDrilldown::Other(doc_node.kind),
inner: doc_node,
}
}
Expand Down Expand Up @@ -329,6 +339,10 @@ pub fn setup_hbs<'t>() -> Result<Handlebars<'t>, anyhow::Error> {
"pages/search_results",
include_str!("./templates/pages/search_results.hbs"),
)?;
reg.register_template_string(
"pages/redirect",
include_str!("./templates/pages/redirect.hbs"),
)?;

// icons
reg.register_template_string(
Expand Down Expand Up @@ -447,35 +461,59 @@ pub fn generate(
);

files.extend(symbol_pages.into_iter().map(
|(breadcrumbs_ctx, sidepanel_ctx, symbol_group_ctx)| {
let root = ctx.href_resolver.resolve_path(
UrlResolveKind::Symbol {
file: &short_path,
symbol: &symbol_group_ctx.name,
},
UrlResolveKind::Root,
);

let html_head_ctx = pages::HtmlHeadCtx::new(
&root,
&symbol_group_ctx.name,
ctx.package_name.as_ref(),
Some(short_path.clone()),
);

let file_name =
format!("{}/~/{}.html", short_path.as_str(), symbol_group_ctx.name);

let page_ctx = pages::PageCtx {
html_head_ctx,
|symbol_page| match symbol_page {
SymbolPage::Symbol {
breadcrumbs_ctx,
sidepanel_ctx,
symbol_group_ctx,
breadcrumbs_ctx,
};

let symbol_page = ctx.hbs.render("pages/symbol", &page_ctx).unwrap();

(file_name, symbol_page)
} => {
let root = ctx.href_resolver.resolve_path(
UrlResolveKind::Symbol {
file: &short_path,
symbol: &symbol_group_ctx.name,
},
UrlResolveKind::Root,
);

let html_head_ctx = pages::HtmlHeadCtx::new(
&root,
&symbol_group_ctx.name,
ctx.package_name.as_ref(),
Some(short_path.clone()),
);

let file_name = format!(
"{}/~/{}.html",
short_path.as_str(),
symbol_group_ctx.name
);

let page_ctx = pages::PageCtx {
html_head_ctx,
sidepanel_ctx,
symbol_group_ctx,
breadcrumbs_ctx,
};

let symbol_page =
ctx.hbs.render("pages/symbol", &page_ctx).unwrap();

(file_name, symbol_page)
}
SymbolPage::Redirect {
current_symbol,
href,
} => {
let symbol_page = ctx
.hbs
.render("pages/redirect", &serde_json::json!({ "path": href }))
.unwrap();

let file_name =
format!("{}/~/{}.html", short_path.as_str(), current_symbol);

(file_name, symbol_page)
}
},
));

Expand Down
Loading
Loading