Skip to content

Commit 298a993

Browse files
Nero5023facebook-github-bot
authored andcommitted
Add support for DocModule returned in the items of ForzenModule
Summary: # This diff stack Separate the rules at https://buck2.build/docs/prelude/globals/ into separate pages. Each page will have it's own page. With such change it will be more clean and it will be faster to open the page. # This diff This diff add support return `DocModule` for the items of FrozenModule in `.documentation`. In later diffs, we would use `namespace` to get the documentation. It would return `DocModule`. Without this change, we would not get the docs for inner of namespace Reviewed By: JakobDegen Differential Revision: D73931900 fbshipit-source-id: 6f54cf7b489b0e870a088eabe0ff663c6d838057
1 parent 88b595d commit 298a993

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

starlark/src/docs.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use crate::eval::runtime::params::display::iter_fmt_param_spec;
3939
use crate::typing::Ty;
4040
use crate::values::StarlarkValue;
4141
use crate::values::Trace;
42-
use crate::values::Value;
4342
use crate::values::type_repr::StarlarkTypeRepr;
4443

4544
/// The documentation provided by a user for a specific module, object, function, etc.
@@ -206,20 +205,6 @@ pub enum DocMember {
206205
Function(DocFunction),
207206
}
208207

209-
impl DocMember {
210-
pub(crate) fn from_value(value: Value) -> Self {
211-
// If we have a value which is a complex type, the right type to put in the docs is not the type
212-
// it represents, but it's just a property we should point at
213-
match value.documentation() {
214-
DocItem::Member(x) => x,
215-
_ => DocMember::Property(DocProperty {
216-
docs: None,
217-
typ: value.get_type_starlark_repr(),
218-
}),
219-
}
220-
}
221-
}
222-
223208
/// The documentation for a type
224209
///
225210
/// This is distinct from a module since, well, types and modules are different things, but more

starlark/src/environment/modules.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use crate::collections::Hashed;
3636
use crate::docs::DocItem;
3737
use crate::docs::DocMember;
3838
use crate::docs::DocModule;
39+
use crate::docs::DocProperty;
3940
use crate::docs::DocString;
4041
use crate::docs::DocStringKind;
4142
use crate::environment::EnvironmentError;
@@ -242,10 +243,17 @@ impl FrozenModule {
242243
})
243244
// FIXME(JakobDegen): Throws out information
244245
.map(|(k, v)| {
245-
(
246-
k.as_str().to_owned(),
247-
DocItem::Member(DocMember::from_value(v.to_value())),
248-
)
246+
let doc_item = match v.to_value().documentation() {
247+
doc_module @ DocItem::Module(_) => doc_module,
248+
member @ DocItem::Member(_) => member,
249+
// If we have a value which is a complex type, the right type to put in the docs is not the type
250+
// it represents, but it's just a property we should point at
251+
DocItem::Type(_) => DocItem::Member(DocMember::Property(DocProperty {
252+
docs: None,
253+
typ: v.to_value().get_type_starlark_repr(),
254+
})),
255+
};
256+
(k.as_str().to_owned(), doc_item)
249257
})
250258
.collect();
251259

0 commit comments

Comments
 (0)