-
-
Notifications
You must be signed in to change notification settings - Fork 113
parser: Add doc format support #1641
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
base: main
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 |
|---|---|---|
|
|
@@ -6,3 +6,4 @@ extend-exclude = ["*.svg"] | |
| gir = "gir" | ||
| inout = "inout" | ||
| serde = "serde" | ||
| typ = "typ" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,6 @@ target_path = "." | |
| # auto_path = "src/auto" | ||
| work_mode = "normal" | ||
| # Whether the library uses https://gitlab.gnome.org/GNOME/gi-docgen for its documentation | ||
| use_gi_docgen = false | ||
| generate_safety_asserts = true | ||
| deprecate_by_min_version = true | ||
| # With this option enabled, versions for gir and gir-files saved only to one file to minimize noise, | ||
|
|
@@ -123,7 +122,7 @@ visibility = "pub" # or 'crate' / 'private' / 'super' | |
| # works for flags and enums. You have to pass the "GIR" member name. | ||
| default_value = "fill" | ||
| # Change the name of the generated trait to e.g avoid naming conflicts | ||
| trait_name = "TraitnameExt" | ||
| trait_name = "TraitnameExt" | ||
| # In case you don't want to generate the documentation for this type. | ||
| generate_doc = false | ||
| # define overrides for function | ||
|
|
@@ -336,7 +335,7 @@ status = "generate" | |
| name = "stock_list_ids" | ||
| # allows to ignore global functions | ||
| ignore = true | ||
| # allows to define if the function was moved to a trait | ||
| # allows to define if the function was moved to a trait | ||
|
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. These could go in a separate commit. |
||
| doc_trait_name = "StockExt" | ||
| # allows to define if the function was moved to a struct | ||
| doc_struct_name = "Stock" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,9 @@ use super::{gi_docgen, LocationInObject}; | |
| use crate::{ | ||
| analysis::functions::Info, | ||
| library::{FunctionKind, TypeId}, | ||
| nameutil, Env, | ||
| nameutil, | ||
| parser::DocFormat, | ||
| Env, | ||
| }; | ||
|
|
||
| const LANGUAGE_SEP_BEGIN: &str = "<!-- language=\""; | ||
|
|
@@ -138,7 +140,7 @@ fn replace_symbols( | |
| env: &Env, | ||
| in_type: Option<(&TypeId, Option<LocationInObject>)>, | ||
| ) -> String { | ||
| if env.config.use_gi_docgen { | ||
| if env.library.doc_format == DocFormat::GiDocgen { | ||
|
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. Perhaps for now this could be a 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. that is an option yes, although, it will end up staying there given no one will remember to remove it. As this option only impacts docs generation, i rather have bindings manually amend the format into the gir file then gir keeping this old "hack" 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. My fear is that this is a bit of a chicken and egg situation. Breaking gir generation is a discouragement for setting doc_format and this MR depends on libraries using it. I suppose an alternative is to have a prequel for this PR that just reads the doc_format and does nothing with it (instead of crashing) to unblock the situation, such a MR would not depend on gir-files. 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. It is always been like that when it comes to new annotations so i rather fix things properly. |
||
| let out = gi_docgen::replace_c_types(input, env, in_type); | ||
| let out = gi_docgen_symbol().replace_all(&out, |caps: &Captures<'_>| match &caps[2] { | ||
| "TRUE" => "[`true`]".to_string(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,31 @@ use crate::{ | |
| xmlparser::{Element, XmlParser}, | ||
| }; | ||
|
|
||
| #[derive(Clone, Debug, Default, PartialEq, Eq)] | ||
| pub enum DocFormat { | ||
| GtkDocMarkdown, | ||
| GtkDocDocbook, | ||
| GiDocgen, | ||
| HotDoc, | ||
|
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. This should be Hotdoc if the key is not hot-doc. |
||
| #[default] | ||
| Unknown, | ||
| } | ||
|
|
||
| impl std::str::FromStr for DocFormat { | ||
| type Err = String; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| match s { | ||
| "gtk-doc-markdown" => Ok(Self::GtkDocMarkdown), | ||
| "gtk-doc-docbook" => Ok(Self::GtkDocDocbook), | ||
| "gi-docgen" => Ok(Self::GiDocgen), | ||
| "hotdoc" => Ok(Self::HotDoc), | ||
| "unknown" => Ok(Self::Unknown), | ||
| e => Err(format!("Invalid doc:format {e}")), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const EMPTY_CTYPE: &str = "/*EMPTY*/"; | ||
|
|
||
| pub fn is_empty_c_type(c_type: &str) -> bool { | ||
|
|
@@ -81,6 +106,11 @@ impl Library { | |
| std::mem::take(&mut includes), | ||
| ), | ||
| "attribute" => parser.ignore_element(), | ||
| "doc" => { | ||
| let format = DocFormat::from_str(elem.attr_required("name")?)?; | ||
| self.doc_format = format; | ||
| Ok(()) | ||
| } | ||
| _ => Err(parser.unexpected_element(elem)), | ||
| })?; | ||
| Ok(()) | ||
|
|
||
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.
It's going to take a while until everything uses this so for the time being maybe change
use_gi_docgentodoc_formatand allow the same values there, and don't make the attribute in the XML mandatory yet?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.
What is everything? It is GTK, GLib, Pango and libadwaita (merged already https://gitlab.gnome.org/GNOME/libadwaita/-/merge_requests/1428).
The remaining bindings don't get updated often at all.
If you just want to ignore the element for now, it could be done in a separate patch by someone else.
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.
If everything using gi-docgen is updated then that's fine with me. Just default to "unknown" if the attribute is not in the XML.