Add Engine::gen_fn_metadata_with_ast_to_json.
This commit is contained in:
parent
ff67efc6d5
commit
8c41e549f7
@ -10,8 +10,9 @@ Each function defined in an `AST` can optionally attach _doc-comments_ (which, a
|
||||
are comments prefixed by either `///` or `/**`). Doc-comments allow third-party tools to
|
||||
automatically generate documentation for functions defined in a Rhai script.
|
||||
|
||||
A new API, `Engine::gen_fn_metadata_to_json`, paired with the new `metadata` feature,
|
||||
exports the full list of functions metadata (including those in an `AST`) as a JSON document.
|
||||
A new API, `Engine::gen_fn_metadata_to_json` and `Engine::gen_fn_metadata_with_ast_to_json`,
|
||||
paired with the new `metadata` feature, exports the full list of functions metadata
|
||||
(including those in an `AST`) as a JSON document.
|
||||
|
||||
Bug fixes
|
||||
---------
|
||||
@ -36,7 +37,7 @@ New features
|
||||
|
||||
* `AST::iter_functions` now returns `ScriptFnMetadata` which includes, among others, _doc-comments_ for functions prefixed by `///` or `/**`.
|
||||
* _Doc-comments_ can be enabled/disabled with the new `Engine::set_doc_comments` method.
|
||||
* A new feature `metadata` is added that pulls in `serde_json` and enables `Engine::gen_fn_metadata_to_json` which exports the full list of functions metadata (including those inside an `AST`) in JSON format.
|
||||
* A new feature `metadata` is added that pulls in `serde_json` and enables `Engine::gen_fn_metadata_to_json` and ``Engine::gen_fn_metadata_with_ast_to_json` which exports the full list of functions metadata (including those inside an `AST`) in JSON format.
|
||||
* `Engine::on_debug` provides two additional parameters: `source: Option<&str>` and `pos: Position`.
|
||||
* `NativeCallContext` and `EvalContext` both expose `source()` which returns the current source, if any.
|
||||
|
||||
|
@ -213,17 +213,17 @@ impl From<&crate::Module> for ModuleMetadata {
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl Engine {
|
||||
/// Generate a list of all functions (including those defined in an [`AST`][crate::AST], if provided)
|
||||
/// Generate a list of all functions (including those defined in an [`AST`][crate::AST])
|
||||
/// in JSON format. Available only under the `metadata` feature.
|
||||
///
|
||||
/// Functions from the following sources are included:
|
||||
/// 1) Functions defined in an [`AST`][crate::AST] (if provided)
|
||||
/// 1) Functions defined in an [`AST`][crate::AST]
|
||||
/// 2) Functions registered into the global namespace
|
||||
/// 3) Functions in registered sub-modules
|
||||
/// 4) Functions in packages (optional)
|
||||
pub fn gen_fn_metadata_to_json(
|
||||
pub fn gen_fn_metadata_with_ast_to_json(
|
||||
&self,
|
||||
ast: Option<&AST>,
|
||||
ast: &AST,
|
||||
include_packages: bool,
|
||||
) -> serde_json::Result<String> {
|
||||
let mut global: ModuleMetadata = Default::default();
|
||||
@ -254,4 +254,15 @@ impl Engine {
|
||||
|
||||
serde_json::to_string_pretty(&global)
|
||||
}
|
||||
|
||||
/// Generate a list of all functions in JSON format.
|
||||
/// Available only under the `metadata` feature.
|
||||
///
|
||||
/// Functions from the following sources are included:
|
||||
/// 1) Functions registered into the global namespace
|
||||
/// 2) Functions in registered sub-modules
|
||||
/// 3) Functions in packages (optional)
|
||||
pub fn gen_fn_metadata_to_json(&self, include_packages: bool) -> serde_json::Result<String> {
|
||||
self.gen_fn_metadata_with_ast_to_json(&Default::default(), include_packages)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user