Fix compilation bug.
This commit is contained in:
parent
65621b79b1
commit
6b5a14ee88
@ -2,7 +2,6 @@ use crate::stdlib::{
|
|||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
collections::BTreeMap,
|
collections::BTreeMap,
|
||||||
string::{String, ToString},
|
string::{String, ToString},
|
||||||
vec,
|
|
||||||
vec::Vec,
|
vec::Vec,
|
||||||
};
|
};
|
||||||
use crate::{Engine, AST};
|
use crate::{Engine, AST};
|
||||||
@ -89,7 +88,7 @@ struct FnMetadata {
|
|||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
pub return_type: Option<String>,
|
pub return_type: Option<String>,
|
||||||
pub signature: String,
|
pub signature: String,
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
pub doc_comments: Vec<String>,
|
pub doc_comments: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,8 +124,8 @@ impl From<&crate::module::FuncInfo> for FnMetadata {
|
|||||||
FnType::Native
|
FnType::Native
|
||||||
},
|
},
|
||||||
num_params: info.params,
|
num_params: info.params,
|
||||||
params: if let Some(ref names) = info.param_names {
|
params: info
|
||||||
names
|
.param_names
|
||||||
.iter()
|
.iter()
|
||||||
.take(info.params)
|
.take(info.params)
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
@ -138,18 +137,12 @@ impl From<&crate::module::FuncInfo> for FnMetadata {
|
|||||||
let typ = seg.next().map(|s| s.trim().to_string());
|
let typ = seg.next().map(|s| s.trim().to_string());
|
||||||
FnParam { name, typ }
|
FnParam { name, typ }
|
||||||
})
|
})
|
||||||
.collect()
|
.collect(),
|
||||||
} else {
|
return_type: info
|
||||||
vec![]
|
.param_names
|
||||||
},
|
|
||||||
return_type: if let Some(ref names) = info.param_names {
|
|
||||||
names
|
|
||||||
.last()
|
.last()
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
.or_else(|| Some("()".to_string()))
|
.or_else(|| Some("()".to_string())),
|
||||||
} else {
|
|
||||||
None
|
|
||||||
},
|
|
||||||
signature: info.gen_signature(),
|
signature: info.gen_signature(),
|
||||||
doc_comments: if info.func.is_script() {
|
doc_comments: if info.func.is_script() {
|
||||||
info.func.get_fn_def().comments.clone()
|
info.func.get_fn_def().comments.clone()
|
||||||
@ -178,11 +171,7 @@ impl From<crate::ScriptFnMetadata<'_>> for FnMetadata {
|
|||||||
.collect(),
|
.collect(),
|
||||||
return_type: Some("Dynamic".to_string()),
|
return_type: Some("Dynamic".to_string()),
|
||||||
signature: info.to_string(),
|
signature: info.to_string(),
|
||||||
doc_comments: if info.comments.is_empty() {
|
doc_comments: info.comments.iter().map(|s| s.to_string()).collect(),
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(info.comments.iter().map(|s| s.to_string()).collect())
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -211,10 +200,10 @@ impl From<&crate::Module> for ModuleMetadata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "metadata")]
|
||||||
impl Engine {
|
impl Engine {
|
||||||
/// Generate a list of all functions (including those defined in an [`AST`][crate::AST])
|
/// _(METADATA)_ Generate a list of all functions (including those defined in an
|
||||||
/// in JSON format. Available only under the `metadata` feature.
|
/// [`AST`][crate::AST]) in JSON format. Available only under the `metadata` feature.
|
||||||
///
|
///
|
||||||
/// Functions from the following sources are included:
|
/// Functions from the following sources are included:
|
||||||
/// 1) Functions defined in an [`AST`][crate::AST]
|
/// 1) Functions defined in an [`AST`][crate::AST]
|
||||||
@ -244,11 +233,9 @@ impl Engine {
|
|||||||
.map(|f| f.into())
|
.map(|f| f.into())
|
||||||
.for_each(|info| global.functions.push(info));
|
.for_each(|info| global.functions.push(info));
|
||||||
|
|
||||||
if let Some(ast) = ast {
|
|
||||||
ast.iter_functions()
|
ast.iter_functions()
|
||||||
.map(|f| f.into())
|
.map(|f| f.into())
|
||||||
.for_each(|info| global.functions.push(info));
|
.for_each(|info| global.functions.push(info));
|
||||||
}
|
|
||||||
|
|
||||||
global.functions.sort();
|
global.functions.sort();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user