Skip to content

Commit ecc70d3

Browse files
committed
fix: matching arguments with docs for format *args and **kwargs
1 parent 3b644ce commit ecc70d3

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

starlark/src/docs/mod.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -509,14 +509,21 @@ impl DocFunction {
509509
Some(args) => {
510510
let entries = Self::parse_params(kind, args);
511511
for x in &mut params {
512-
match x {
513-
DocParam::Arg { name, docs, .. }
514-
| DocParam::Args { name, docs, .. }
515-
| DocParam::Kwargs { name, docs, .. } => match entries.get(name) {
516-
Some(raw) => *docs = DocString::from_docstring(kind, raw),
517-
_ => (),
518-
},
519-
_ => (),
512+
if let Some((docs, raw)) = match x {
513+
DocParam::Arg { name, docs, .. } => {
514+
entries.get(name).map(|raw| (docs, raw))
515+
}
516+
DocParam::Args { name, docs, .. } => entries
517+
.get(name)
518+
.or_else(|| entries.get(&format!("*{}", name)))
519+
.map(|raw| (docs, raw)),
520+
DocParam::Kwargs { name, docs, .. } => entries
521+
.get(name)
522+
.or_else(|| entries.get(&format!("**{}", name)))
523+
.map(|raw| (docs, raw)),
524+
_ => None,
525+
} {
526+
*docs = DocString::from_docstring(kind, raw);
520527
}
521528
}
522529
}

starlark_lsp/src/docs.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,28 @@ pub(crate) fn get_doc_item_for_def<P: AstPayload>(def: &DefP<P>) -> Option<DocFu
3838
.params
3939
.iter()
4040
.filter_map(|param| match &param.node {
41-
ParameterP::Normal(p, _)
42-
| ParameterP::WithDefaultValue(p, _, _)
43-
| ParameterP::Args(p, _)
44-
| ParameterP::KwArgs(p, _) => Some(DocParam::Arg {
41+
ParameterP::Normal(p, _) => Some(DocParam::Arg {
4542
name: p.ident.to_owned(),
4643
docs: None,
4744
typ: Ty::any(),
4845
default_value: None,
4946
}),
47+
ParameterP::Args(p, _) => Some(DocParam::Args {
48+
name: p.ident.to_owned(),
49+
docs: None,
50+
typ: Ty::any(),
51+
}),
52+
ParameterP::KwArgs(p, _) => Some(DocParam::Kwargs {
53+
name: p.ident.to_owned(),
54+
docs: None,
55+
typ: Ty::any(),
56+
}),
57+
ParameterP::WithDefaultValue(p, _, _) => Some(DocParam::Arg {
58+
name: p.ident.to_owned(),
59+
docs: None,
60+
typ: Ty::any(),
61+
default_value: Some("_".to_owned()),
62+
}),
5063
_ => None,
5164
})
5265
.collect();

0 commit comments

Comments
 (0)