-
Notifications
You must be signed in to change notification settings - Fork 884
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
Allow rustup doc books open subsections and paragraphs #3380
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1586,22 +1586,38 @@ fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> { | |
}; | ||
|
||
let topical_path: PathBuf; | ||
|
||
let doc_url = if let Some(topic) = m.get_one::<String>("topic") { | ||
topical_path = topical_doc::local_path(&toolchain.doc_path("").unwrap(), topic)?; | ||
topical_path.to_str().unwrap() | ||
} else if let Some((_, _, path)) = DOCS_DATA.iter().find(|(name, _, _)| m.get_flag(name)) { | ||
path | ||
} else { | ||
"index.html" | ||
}; | ||
let cached_path: String; | ||
let mut has_docs_data_link = false; | ||
|
||
let doc_url = | ||
if let Some((short, _, path)) = DOCS_DATA.iter().find(|(name, _, _)| m.get_flag(name)) { | ||
if let Some(topic) = m.get_one::<String>("topic") { | ||
has_docs_data_link = true; | ||
cached_path = format!("{}/{}", short, topic); | ||
cached_path.as_str() | ||
} else { | ||
path | ||
} | ||
} else if let Some(topic) = m.get_one::<String>("topic") { | ||
topical_path = topical_doc::local_path(&toolchain.doc_path("").unwrap(), topic)?; | ||
topical_path.to_str().unwrap() | ||
} else { | ||
"index.html" | ||
}; | ||
|
||
if m.get_flag("path") { | ||
let doc_path = toolchain.doc_path(doc_url)?; | ||
writeln!(process().stdout().lock(), "{}", doc_path.display())?; | ||
Ok(utils::ExitCode(0)) | ||
} else { | ||
toolchain.open_docs(doc_url)?; | ||
if has_docs_data_link { | ||
let url_path_buf = toolchain.doc_path(doc_url)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can put it into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have tried to use So I had to use Or maybe we should go further and prepend "file:///" everywhere? |
||
let url_path = format!("file:///{}", url_path_buf.to_str().unwrap()); | ||
let doc_path = Path::new(&url_path); | ||
utils::open_browser(doc_path)? | ||
} else { | ||
toolchain.open_docs(doc_url)?; | ||
} | ||
Ok(utils::ExitCode(0)) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to define this one here? Maybe we can put it into the
if
statement.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the way to resolve &str borrowing issue. If we put this definition into if statement we will get error:
error[E0597]:
cached_path
does not live long enough. because source String must live as long as let doc_url lives.TBH I just used the same workaround that is already used with
let topical_path: PathBuf;
one line above.maybe there is a nicer way to solve this.