gpui: Store action documentation (#33809)

Closes #ISSUE

Adds a new `documentation` method to actions, that is extracted from doc
comments when using the `actions!` or derive macros.

Additionally, this PR adds doc comments to as many action definitions in
Zed as possible.

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Ben Kunkle 2025-07-02 20:14:33 -05:00 committed by GitHub
parent def8bab5a8
commit 6cd4dbdea1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
96 changed files with 1467 additions and 78 deletions

View file

@ -14,6 +14,7 @@ pub(crate) fn derive_action(input: TokenStream) -> TokenStream {
let mut no_register = false;
let mut namespace = None;
let mut deprecated = None;
let mut doc_str: Option<String> = None;
for attr in &input.attrs {
if attr.path().is_ident("action") {
@ -74,6 +75,22 @@ pub(crate) fn derive_action(input: TokenStream) -> TokenStream {
Ok(())
})
.unwrap_or_else(|e| panic!("in #[action] attribute: {}", e));
} else if attr.path().is_ident("doc") {
use syn::{Expr::Lit, ExprLit, Lit::Str, Meta, MetaNameValue};
if let Meta::NameValue(MetaNameValue {
value:
Lit(ExprLit {
lit: Str(ref lit_str),
..
}),
..
}) = attr.meta
{
let doc = lit_str.value();
let doc_str = doc_str.get_or_insert_default();
doc_str.push_str(doc.trim());
doc_str.push('\n');
}
}
}
@ -122,6 +139,13 @@ pub(crate) fn derive_action(input: TokenStream) -> TokenStream {
quote! { None }
};
let documentation_fn_body = if let Some(doc) = doc_str {
let doc = doc.trim();
quote! { Some(#doc) }
} else {
quote! { None }
};
let registration = if no_register {
quote! {}
} else {
@ -171,6 +195,10 @@ pub(crate) fn derive_action(input: TokenStream) -> TokenStream {
fn deprecation_message() -> Option<&'static str> {
#deprecation_fn_body
}
fn documentation() -> Option<&'static str> {
#documentation_fn_body
}
}
})
}

View file

@ -34,6 +34,7 @@ pub(crate) fn generate_register_action(type_name: &Ident) -> TokenStream2 {
json_schema: <#type_name as gpui::Action>::action_json_schema,
deprecated_aliases: <#type_name as gpui::Action>::deprecated_aliases(),
deprecation_message: <#type_name as gpui::Action>::deprecation_message(),
documentation: <#type_name as gpui::Action>::documentation(),
}
}