Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/kcl-lib/src/docs/kcl_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ impl ArgData {
let mut result = ArgData {
snippet_array: Default::default(),
name: arg.identifier.name.clone(),
ty: arg.type_.as_ref().map(|t| t.to_string()),
ty: arg.param_type.as_ref().map(|t| t.to_string()),
docs: None,
override_in_snippet: None,
kind: if arg.labeled {
Expand Down
11 changes: 7 additions & 4 deletions rust/kcl-lib/src/execution/fn_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,16 @@ impl<'a> From<&'a FunctionSource> for FunctionDefinition<'a> {
let mut named_args = IndexMap::new();
for p in &ast.params {
if !p.labeled {
input_arg = Some((p.identifier.name.clone(), p.type_.as_ref().map(|t| t.inner.clone())));
input_arg = Some((
p.identifier.name.clone(),
p.param_type.as_ref().map(|t| t.inner.clone()),
));
continue;
}

named_args.insert(
p.identifier.name.clone(),
(p.default_value.clone(), p.type_.as_ref().map(|t| t.inner.clone())),
(p.default_value.clone(), p.param_type.as_ref().map(|t| t.inner.clone())),
);
}

Expand Down Expand Up @@ -899,7 +902,7 @@ mod test {
fn opt_param(s: &'static str) -> Parameter {
Parameter {
identifier: ident(s),
type_: None,
param_type: None,
default_value: Some(DefaultParamVal::none()),
labeled: true,
digest: None,
Expand All @@ -908,7 +911,7 @@ mod test {
fn req_param(s: &'static str) -> Parameter {
Parameter {
identifier: ident(s),
type_: None,
param_type: None,
default_value: None,
labeled: true,
digest: None,
Expand Down
4 changes: 2 additions & 2 deletions rust/kcl-lib/src/lsp/kcl/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ impl FunctionExpression {
return Some(h);
}
for arg in &self.params {
if let Some(ty) = &arg.type_
if let Some(ty) = &arg.param_type
&& let Some(h) = ty.get_hover_value_for_position(pos, code, opts)
{
return Some(h);
Expand All @@ -342,7 +342,7 @@ impl FunctionExpression {
if let Some(value) = self.body.get_expr_for_position(pos) {
let mut vars = opts.vars.clone().unwrap_or_default();
for arg in &self.params {
let ty = arg.type_.as_ref().map(|ty| ty.to_string());
let ty = arg.param_type.as_ref().map(|ty| ty.to_string());
vars.insert(arg.identifier.inner.name.clone(), ty);
}
return value.get_hover_value_for_position(
Expand Down
1 change: 1 addition & 0 deletions rust/kcl-lib/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ async fn main() {
.unwrap();
let mut exec_state = ExecState::new(&ctx);
ctx.run(&program, &mut exec_state).await.map_err(|e| e.error).unwrap();
println!("{:#?}", exec_state.errors());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably be eprintln and should be wrapped in if !exec_state.errors().is_empty()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output from main.rs is very debug-y and I found it useful to have the [] as an indicator of no errors.

To be pedantic, it's reporting an error with the user's code not reporting an error with the program, so I think it should be using print rather than eprint

}
2 changes: 1 addition & 1 deletion rust/kcl-lib/src/parsing/ast/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl FunctionType {
impl Parameter {
compute_digest!(|slf, hasher| {
hasher.update(slf.identifier.compute_digest());
match &mut slf.type_ {
match &mut slf.param_type {
Some(arg) => {
hasher.update(b"Parameter::type_::Some");
hasher.update(arg.compute_digest())
Expand Down
30 changes: 15 additions & 15 deletions rust/kcl-lib/src/parsing/ast/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3330,8 +3330,8 @@ pub struct Parameter {
pub identifier: Node<Identifier>,
/// The type of the parameter.
/// This is optional if the user defines a type.
#[serde(skip)]
pub type_: Option<Node<Type>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub param_type: Option<Node<Type>>,
/// Is the parameter optional?
/// If so, what is its default value?
/// If this is None, then the parameter is required.
Expand Down Expand Up @@ -3887,15 +3887,15 @@ cylinder = startSketchOn(-XZ)
let params = &func_expr.params;
assert_eq!(params.len(), 3);
assert_eq!(
params[0].type_.as_ref().unwrap().inner,
params[0].param_type.as_ref().unwrap().inner,
Type::Primitive(PrimitiveType::Number(NumericSuffix::Mm))
);
assert_eq!(
params[1].type_.as_ref().unwrap().inner,
params[1].param_type.as_ref().unwrap().inner,
Type::Primitive(PrimitiveType::String)
);
assert_eq!(
params[2].type_.as_ref().unwrap().inner,
params[2].param_type.as_ref().unwrap().inner,
Type::Primitive(PrimitiveType::String)
);
}
Expand All @@ -3918,21 +3918,21 @@ cylinder = startSketchOn(-XZ)
let params = &func_expr.params;
assert_eq!(params.len(), 3);
assert_eq!(
params[0].type_.as_ref().unwrap().inner,
params[0].param_type.as_ref().unwrap().inner,
Type::Array {
ty: Box::new(Type::Primitive(PrimitiveType::Number(NumericSuffix::None))),
len: ArrayLen::None
}
);
assert_eq!(
params[1].type_.as_ref().unwrap().inner,
params[1].param_type.as_ref().unwrap().inner,
Type::Array {
ty: Box::new(Type::Primitive(PrimitiveType::String)),
len: ArrayLen::None
}
);
assert_eq!(
params[2].type_.as_ref().unwrap().inner,
params[2].param_type.as_ref().unwrap().inner,
Type::Primitive(PrimitiveType::String)
);
}
Expand All @@ -3956,14 +3956,14 @@ cylinder = startSketchOn(-XZ)
let params = &func_expr.params;
assert_eq!(params.len(), 3);
assert_eq!(
params[0].type_.as_ref().unwrap().inner,
params[0].param_type.as_ref().unwrap().inner,
Type::Array {
ty: Box::new(Type::Primitive(PrimitiveType::Number(NumericSuffix::None))),
len: ArrayLen::None
}
);
assert_eq!(
params[1].type_.as_ref().unwrap().inner,
params[1].param_type.as_ref().unwrap().inner,
Type::Object {
properties: vec![
(
Expand Down Expand Up @@ -4019,7 +4019,7 @@ cylinder = startSketchOn(-XZ)
}
);
assert_eq!(
params[2].type_.as_ref().unwrap().inner,
params[2].param_type.as_ref().unwrap().inner,
Type::Primitive(PrimitiveType::String)
);
}
Expand All @@ -4046,7 +4046,7 @@ cylinder = startSketchOn(-XZ)
name: "foo".to_owned(),
digest: None,
}),
type_: None,
param_type: None,
default_value: None,
labeled: true,
digest: None,
Expand All @@ -4065,7 +4065,7 @@ cylinder = startSketchOn(-XZ)
name: "foo".to_owned(),
digest: None,
}),
type_: None,
param_type: None,
default_value: Some(DefaultParamVal::none()),
labeled: true,
digest: None,
Expand All @@ -4085,7 +4085,7 @@ cylinder = startSketchOn(-XZ)
name: "foo".to_owned(),
digest: None,
}),
type_: None,
param_type: None,
default_value: None,
labeled: true,
digest: None,
Expand All @@ -4095,7 +4095,7 @@ cylinder = startSketchOn(-XZ)
name: "bar".to_owned(),
digest: None,
}),
type_: None,
param_type: None,
default_value: Some(DefaultParamVal::none()),
labeled: true,
digest: None,
Expand Down
14 changes: 7 additions & 7 deletions rust/kcl-lib/src/parsing/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3181,7 +3181,7 @@ fn parameters(i: &mut TokenSlice) -> ModalResult<Vec<Parameter>> {

Ok(Parameter {
identifier,
type_,
param_type: type_,
default_value,
labeled,
digest: None,
Expand Down Expand Up @@ -4612,7 +4612,7 @@ e
name: "a".to_owned(),
digest: None,
}),
type_: None,
param_type: None,
default_value: Some(DefaultParamVal::none()),
labeled: true,
digest: None,
Expand All @@ -4625,7 +4625,7 @@ e
name: "a".to_owned(),
digest: None,
}),
type_: None,
param_type: None,
default_value: None,
labeled: true,
digest: None,
Expand All @@ -4639,7 +4639,7 @@ e
name: "a".to_owned(),
digest: None,
}),
type_: None,
param_type: None,
default_value: None,
labeled: true,
digest: None,
Expand All @@ -4649,7 +4649,7 @@ e
name: "b".to_owned(),
digest: None,
}),
type_: None,
param_type: None,
default_value: Some(DefaultParamVal::none()),
labeled: true,
digest: None,
Expand All @@ -4664,7 +4664,7 @@ e
name: "a".to_owned(),
digest: None,
}),
type_: None,
param_type: None,
default_value: Some(DefaultParamVal::none()),
labeled: true,
digest: None,
Expand All @@ -4674,7 +4674,7 @@ e
name: "b".to_owned(),
digest: None,
}),
type_: None,
param_type: None,
default_value: None,
labeled: true,
digest: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ expression: actual
"start": 7,
"type": "Identifier"
},
"param_type": {
"None": null,
"commentStart": 11,
"end": 17,
"moduleId": 0,
"p_type": "Number",
"start": 11,
"type": "Primitive"
},
"default_value": {
"commentStart": 20,
"end": 21,
Expand Down
2 changes: 1 addition & 1 deletion rust/kcl-lib/src/unparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ impl Parameter {
if self.default_value.is_some() {
buf.push('?');
};
if let Some(ty) = &self.type_ {
if let Some(ty) = &self.param_type {
buf.push_str(": ");
write!(buf, "{ty}").no_fail();
}
Expand Down
28 changes: 28 additions & 0 deletions rust/kcl-lib/tests/any_type/ast.snap
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ description: Result of parsing any_type.kcl
"start": 0,
"type": "Identifier"
},
"param_type": {
"commentStart": 0,
"end": 0,
"moduleId": 0,
"p_type": "Any",
"start": 0,
"type": "Primitive"
},
"labeled": false
}
],
Expand Down Expand Up @@ -157,6 +165,14 @@ description: Result of parsing any_type.kcl
"start": 0,
"type": "Identifier"
},
"param_type": {
"commentStart": 0,
"end": 0,
"moduleId": 0,
"p_type": "Any",
"start": 0,
"type": "Primitive"
},
"labeled": false
}
],
Expand Down Expand Up @@ -388,6 +404,18 @@ description: Result of parsing any_type.kcl
"start": 0,
"type": "Identifier"
},
"param_type": {
"commentStart": 0,
"end": 0,
"len": "None",
"moduleId": 0,
"start": 0,
"ty": {
"type": "Primitive",
"p_type": "Any"
},
"type": "Array"
},
"labeled": false
}
],
Expand Down
9 changes: 9 additions & 0 deletions rust/kcl-lib/tests/kcl_samples/cycloidal-gear/ast.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,15 @@ description: Result of parsing cycloidal-gear.kcl
"name": "helixAngle",
"start": 0,
"type": "Identifier"
},
"param_type": {
"Deg": null,
"commentStart": 0,
"end": 0,
"moduleId": 0,
"p_type": "Number",
"start": 0,
"type": "Primitive"
}
}
],
Expand Down
Loading