Suggest a list of possible arg labels when an argument is unlabelled (#6755)

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2025-05-09 14:28:04 +12:00
committed by GitHub
parent 1ea66d6f23
commit 923feadfa5
16 changed files with 139 additions and 69 deletions

View File

@ -488,7 +488,9 @@ impl CallExpressionKw {
}
hasher.update(slf.arguments.len().to_ne_bytes());
for argument in slf.arguments.iter_mut() {
hasher.update(argument.label.compute_digest());
if let Some(l) = &mut argument.label {
hasher.update(l.compute_digest());
}
hasher.update(argument.arg.compute_digest());
}
});

View File

@ -460,10 +460,12 @@ impl Node<Program> {
crate::walk::Node::CallExpressionKw(call) => {
if call.inner.callee.inner.name.inner.name == "appearance" {
for arg in &call.arguments {
if arg.label.inner.name == "color" {
// Get the value of the argument.
if let Expr::Literal(literal) = &arg.arg {
add_color(literal);
if let Some(l) = &arg.label {
if l.inner.name == "color" {
// Get the value of the argument.
if let Expr::Literal(literal) = &arg.arg {
add_color(literal);
}
}
}
}
@ -1872,7 +1874,7 @@ pub struct CallExpressionKw {
#[ts(export)]
#[serde(tag = "type")]
pub struct LabeledArg {
pub label: Node<Identifier>,
pub label: Option<Node<Identifier>>,
pub arg: Expr,
}
@ -1917,7 +1919,7 @@ impl CallExpressionKw {
self.unlabeled
.iter()
.map(|e| (None, e))
.chain(self.arguments.iter().map(|arg| (Some(&arg.label), &arg.arg)))
.chain(self.arguments.iter().map(|arg| (arg.label.as_ref(), &arg.arg)))
}
pub fn replace_value(&mut self, source_range: SourceRange, new_value: Expr) {