Skip to content

Commit 1209357

Browse files
committed
Flatten argument iterators at call site
1 parent 4ca839c commit 1209357

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

crates/ark/src/lsp/diagnostics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ fn recurse_call(
824824
fn handle_package_attach_call(node: Node, context: &mut DiagnosticContext) -> anyhow::Result<()> {
825825
// Find the first argument (package name). Positionally for now, no attempt
826826
// at argument matching whatsoever.
827-
let Some(package_node) = node.arguments_values().nth(0) else {
827+
let Some(package_node) = node.arguments_values().flatten().nth(0) else {
828828
return Err(anyhow::anyhow!("Can't unpack attached package argument"));
829829
};
830830

@@ -833,6 +833,7 @@ fn handle_package_attach_call(node: Node, context: &mut DiagnosticContext) -> an
833833
// infrastructure.
834834
if let Some(_) = node
835835
.arguments_names_as_string(context.contents)
836+
.flatten()
836837
.find(|n| n == "character.only")
837838
{
838839
return Ok(());

crates/ark/src/lsp/traits/node.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,12 @@ pub trait NodeExt: Sized {
9494
fn children_of(node: Self) -> impl Iterator<Item = Self>;
9595
fn next_siblings(&self) -> impl Iterator<Item = Self>;
9696
fn arguments(&self) -> impl Iterator<Item = (Option<Self>, Option<Self>)>;
97-
fn arguments_values(&self) -> impl Iterator<Item = Self>;
98-
fn arguments_names(&self) -> impl Iterator<Item = Self>;
99-
fn arguments_names_as_string(&self, contents: &ropey::Rope) -> impl Iterator<Item = String>;
97+
fn arguments_values(&self) -> impl Iterator<Item = Option<Self>>;
98+
fn arguments_names(&self) -> impl Iterator<Item = Option<Self>>;
99+
fn arguments_names_as_string(
100+
&self,
101+
contents: &ropey::Rope,
102+
) -> impl Iterator<Item = Option<String>>;
100103
}
101104

102105
impl<'tree> NodeExt for Node<'tree> {
@@ -277,24 +280,27 @@ impl<'tree> NodeExt for Node<'tree> {
277280
})
278281
}
279282

280-
fn arguments_names(&self) -> impl Iterator<Item = Node<'tree>> {
281-
self.arguments().filter_map(|(name, _value)| name)
283+
fn arguments_names(&self) -> impl Iterator<Item = Option<Node<'tree>>> {
284+
self.arguments().map(|(name, _value)| name)
282285
}
283286

284-
fn arguments_names_as_string(&self, contents: &ropey::Rope) -> impl Iterator<Item = String> {
285-
self.arguments_names().filter_map(|node| -> Option<String> {
286-
match contents.node_slice(&node) {
287+
fn arguments_names_as_string(
288+
&self,
289+
contents: &ropey::Rope,
290+
) -> impl Iterator<Item = Option<String>> {
291+
self.arguments_names().map(|maybe_node| {
292+
maybe_node.and_then(|node| match contents.node_slice(&node) {
287293
Err(err) => {
288294
tracing::error!("Can't convert argument name to text: {err:?}");
289295
None
290296
},
291297
Ok(text) => Some(text.to_string()),
292-
}
298+
})
293299
})
294300
}
295301

296-
fn arguments_values(&self) -> impl Iterator<Item = Node<'tree>> {
297-
self.arguments().filter_map(|(_name, value)| value)
302+
fn arguments_values(&self) -> impl Iterator<Item = Option<Node<'tree>>> {
303+
self.arguments().map(|(_name, value)| value)
298304
}
299305
}
300306

0 commit comments

Comments
 (0)