-
Notifications
You must be signed in to change notification settings - Fork 34
docgen/website: show deprecated function warnings on docs website #584
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
Open
cpu
wants to merge
10
commits into
rustls:main
Choose a base branch
from
cpu:ci/cpu-deprecate-notes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f8866ac
website: check-in generated api.json
cpu de4cfab
ci: check for uncommitted website/static/api.json diffs
cpu c6a848f
ci: run the docs workflow for more triggers
cpu 4adbb82
tools/docgen: simplify process_doc_item format string
cpu ad82ec9
tools/docgen: document comment_and_requirement
cpu 3fad732
tools/docgen: pull out prev_prev once
cpu f14ba77
tools/docgen: simplify comment_and_requirement
cpu 947d8b1
tools/docgen: lift out MetadataItem type, improve crosslinking
cpu 210a3e7
tools/docgen: parse function deprecation messages
cpu 968640d
website: annotate/decorate deprecated items
cpu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,8 @@ struct ItemMetadata { | |
comment: Option<Comment>, | ||
/// A feature requirement that must be enabled for the item | ||
feature: Option<Feature>, | ||
/// A deprecation message for the item | ||
deprecation: Option<Deprecation>, | ||
} | ||
|
||
impl ItemMetadata { | ||
|
@@ -158,15 +160,17 @@ impl ItemMetadata { | |
/// * `prev` is not a comment, and not a feature requirement. | ||
/// * `prev` is a Comment, and has no feature requirement before it. | ||
/// * `prev` is a Comment, and has a feature requirement before it. | ||
/// * `prev` is a Deprecation, and has a comment and feature requirement before it. | ||
/// * `prev` is a Deprecation, and has a comment and no feature requirement before it. | ||
/// * `prev` is a bare feature requirement | ||
/// | ||
/// cbindgen won't create a comment before a feature requirement so we don't have to | ||
/// consider that case. | ||
/// cbindgen won't create other permutations (e.g. comment before a feature requirement, or | ||
/// a deprecation before a feature requirement) so we don't have to consider those cases. | ||
fn new(prev: Node, src: &[u8]) -> Result<Self, Box<dyn Error>> { | ||
let prev_prev = prev.prev_named_sibling(); | ||
|
||
// In the simple case, `prev` is a comment and `prev_prev` may | ||
// be a feature requirement. | ||
// be a feature requirement. Deprecations aren't in play. | ||
if let Ok(comment) = Comment::new(prev, src) { | ||
let feature = match prev_prev { | ||
Some(prev_prev) => Feature::new(prev_prev, src).ok(), | ||
|
@@ -175,24 +179,36 @@ impl ItemMetadata { | |
return Ok(ItemMetadata { | ||
comment: Some(comment), | ||
feature, | ||
deprecation: None, | ||
}); | ||
} | ||
|
||
// If `prev` wasn't a comment, see if it was an expression_statement | ||
// that itself was preceded by a comment. This skips over | ||
// expression-like preprocessor attributes on function decls. | ||
if prev.kind() == "expression_statement" { | ||
return match prev_prev { | ||
Some(prev_prev) => Self::new(prev_prev, src), | ||
None => Ok(ItemMetadata::default()), | ||
// `prev` is a deprecation, `prev_prev` may be a comment, and `prev_prev_prev` | ||
// may be a feature requirement. | ||
if let Ok(deprecation) = Deprecation::new(prev, src) { | ||
let comment = match prev_prev { | ||
Some(prev_prev) => Comment::new(prev_prev, src).ok(), | ||
None => None, | ||
}; | ||
let prev_prev_prev = prev_prev.and_then(|prev_prev| prev_prev.prev_named_sibling()); | ||
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. Consider making this part of the previous |
||
let feature = match prev_prev_prev { | ||
Some(prev_prev_prev) => Feature::new(prev_prev_prev, src).ok(), | ||
None => None, | ||
}; | ||
return Ok(ItemMetadata { | ||
comment, | ||
feature, | ||
deprecation: Some(deprecation), | ||
}); | ||
} | ||
|
||
// If `prev` wasn't a comment, or an expression_statement preceded by a comment, | ||
// then it's either a bare feature requirement or we have no metadata to return. | ||
// then it's either a bare feature requirement without a deprecation or we have no | ||
// metadata to return. | ||
Ok(ItemMetadata { | ||
comment: None, | ||
feature: Feature::new(prev, src).ok(), | ||
deprecation: None, | ||
}) | ||
} | ||
|
||
|
@@ -322,6 +338,39 @@ impl Display for Comment { | |
} | ||
} | ||
|
||
#[derive(Debug, Default, Serialize)] | ||
struct Deprecation(String); | ||
|
||
impl Deprecation { | ||
fn new(node: Node, src: &[u8]) -> Result<Self, Box<dyn Error>> { | ||
require_kind("expression_statement", node, src)?; | ||
|
||
let query_str = r#" | ||
(call_expression | ||
function: (identifier) @func (#eq? @func "DEPRECATED_FUNC") | ||
arguments: (argument_list | ||
(string_literal (string_content) @content) | ||
) | ||
) | ||
"#; | ||
|
||
let mut query_cursor = QueryCursor::new(); | ||
let language = tree_sitter_c::LANGUAGE; | ||
let query = Query::new(&language.into(), query_str)?; | ||
|
||
let captures = query_cursor.captures(&query, node, src); | ||
for (mat, _) in captures { | ||
for capture in mat.captures { | ||
if query.capture_names()[capture.index as usize] == "content" { | ||
return Ok(Self(node_text(capture.node, src))); | ||
} | ||
} | ||
} | ||
|
||
Err(node_error("DEPRECATED_FUNC call not found or malformed", node, src).into()) | ||
} | ||
} | ||
|
||
fn process_typedef_item( | ||
mut metadata: ItemMetadata, | ||
item: Node, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nit: use
.map()
more to avoid theNone => None
branches?