-
-
Notifications
You must be signed in to change notification settings - Fork 223
Generate documentation from doc comments #748
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
Merged
Merged
Changes from all commits
Commits
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
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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright (c) godot-rust; Bromeon and contributors. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
use crate::registry::plugin::PluginItem; | ||
use std::collections::HashMap; | ||
|
||
/// Created for documentation on | ||
/// ```ignore | ||
/// #[derive(GodotClass)] | ||
/// /// Documented | ||
/// struct Struct { | ||
/// /// documented | ||
/// x: f32, | ||
/// } | ||
/// ``` | ||
#[derive(Clone, Copy, Debug, Default)] | ||
pub struct StructDocs { | ||
pub base: &'static str, | ||
pub description: &'static str, | ||
pub members: &'static str, | ||
} | ||
|
||
/// Created for documentation on | ||
/// ```ignore | ||
/// #[godot_api] | ||
/// impl Struct { | ||
/// #[func] | ||
/// /// This function panics! | ||
/// fn panic() -> f32 { panic!() } | ||
/// } | ||
/// ``` | ||
#[derive(Clone, Copy, Debug, Default)] | ||
pub struct InherentImplDocs { | ||
pub methods: &'static str, | ||
pub signals: &'static str, | ||
pub constants: &'static str, | ||
} | ||
|
||
#[derive(Default)] | ||
struct DocPieces { | ||
definition: StructDocs, | ||
inherent: InherentImplDocs, | ||
virtual_methods: &'static str, | ||
} | ||
|
||
#[doc(hidden)] | ||
/// This function scours the registered plugins to find their documentation pieces, | ||
/// and strings them together. | ||
/// | ||
/// It returns an iterator over XML documents. | ||
pub fn gather_xml_docs() -> impl Iterator<Item = String> { | ||
let mut map = HashMap::<&'static str, DocPieces>::new(); | ||
crate::private::iterate_plugins(|x| match x.item { | ||
PluginItem::InherentImpl { | ||
docs: Some(docs), .. | ||
} => map.entry(x.class_name.as_str()).or_default().inherent = docs, | ||
PluginItem::ITraitImpl { | ||
virtual_method_docs, | ||
.. | ||
} => { | ||
map.entry(x.class_name.as_str()) | ||
.or_default() | ||
.virtual_methods = virtual_method_docs | ||
} | ||
PluginItem::Struct { | ||
docs: Some(docs), .. | ||
} => map.entry(x.class_name.as_str()).or_default().definition = docs, | ||
_ => (), | ||
}); | ||
map.into_iter().map(|(class, pieces)| { | ||
let StructDocs { | ||
base, | ||
description, | ||
members, | ||
} = pieces.definition; | ||
|
||
let InherentImplDocs { | ||
methods, | ||
signals, | ||
constants, | ||
} = pieces.inherent; | ||
|
||
let virtual_methods = pieces.virtual_methods; | ||
let brief = description.split_once("[br]").map(|(x, _)| x).unwrap_or_default(); | ||
format!(r#" | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<class name="{class}" inherits="{base}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> | ||
<brief_description>{brief}</brief_description> | ||
<description>{description}</description> | ||
<methods>{methods}{virtual_methods}</methods> | ||
<constants>{constants}</constants> | ||
<signals>{signals}</signals> | ||
<members>{members}</members> | ||
</class>"#) | ||
}, | ||
) | ||
} | ||
|
||
/// # Safety | ||
/// | ||
/// The Godot binding must have been initialized before calling this function. | ||
/// | ||
/// If "experimental-threads" is not enabled, then this must be called from the same thread that the bindings were initialized from. | ||
pub unsafe fn register() { | ||
for xml in gather_xml_docs() { | ||
crate::sys::interface_fn!(editor_help_load_xml_from_utf8_chars_and_len)( | ||
xml.as_ptr() as *const std::ffi::c_char, | ||
xml.len() as i64, | ||
); | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.