MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / misparsed_generic_call

Method misparsed_generic_call

codegraph-kernel/src/dart.rs:1485–1552  ·  view source on GitHub ↗

dartMisparsedGenericCall (dart.ts) — a generic call tree-sitter-dart parsed as two comparisons, `(ref.read < Repo) > (p)`, found from its `<`: the node its callee ends with (under any `await` or prefix operator) and the identifier naming its type argument. Recovered when the type argument names a type and the code is laid out as a call — `<` against the callee, `(` against the `>`. A call chained

(&self, lt: Node<'t>)

Source from the content-addressed store, hash-verified

1483 /// its bare name, which the resolver types from the chain written before
1484 /// it, as it types a parsed chain's `X().m` (#750).
1485 fn misparsed_generic_call(&self, lt: Node<'t>) -> Option<(Node<'t>, Node<'t>)> {
1486 if lt.kind() != "relational_operator" || lt.child(0)?.kind() != "<" {
1487 return None;
1488 }
1489 let inner = lt.parent()?;
1490 let outer = inner.parent()?;
1491 if inner.kind() != "relational_expression" || outer.kind() != "relational_expression" {
1492 return None;
1493 }
1494 let left = outer.named_child(0)?;
1495 if left.start_byte() != inner.start_byte() || left.end_byte() != inner.end_byte() {
1496 return None;
1497 }
1498 let gt = outer.named_child(1)?;
1499 if gt.kind() != "relational_operator" || gt.child(0)?.kind() != ">" {
1500 return None;
1501 }
1502 let args = outer.named_child(2)?;
1503 if !matches!(args.kind(), "parenthesized_expression" | "record_literal") || args.start_byte() != gt.end_byte() {
1504 return None;
1505 }
1506 // A comment against the `<` (`ref.read /* c */<Repo>(p)`) is a
1507 // sibling of its own, so the callee is not against it.
1508 let before = lt.prev_named_sibling()?;
1509 if is_comment(before) || before.end_byte() != lt.start_byte() {
1510 return None;
1511 }
1512 // The type argument: `T`, `p.T`, `T<…>` or `p.T<…>`, and nothing else.
1513 let head = lt.next_named_sibling()?;
1514 if head.kind() != "identifier" {
1515 return None;
1516 }
1517 let mut type_name = head;
1518 let mut rest = head.next_named_sibling();
1519 if let Some(sel) = rest {
1520 let accessor = sel.named_child(0).filter(|a| a.kind() == "unconditional_assignable_selector");
1521 if sel.kind() == "selector" {
1522 if let Some(accessor) = accessor {
1523 let mut ac = accessor.walk();
1524 let name = accessor.named_children(&mut ac).find(|c| c.kind() == "identifier");
1525 type_name = name?;
1526 rest = sel.next_named_sibling();
1527 }
1528 }
1529 }
1530 if let Some(sel) = rest {
1531 let only_type_args = sel.named_child_count() == 1
1532 && sel.named_child(0).map(|t| t.kind() == "type_arguments").unwrap_or(false);
1533 if sel.kind() == "selector" && only_type_args {
1534 rest = sel.next_named_sibling();
1535 }
1536 }
1537 if rest.is_some() {
1538 return None;
1539 }
1540 let name = self.text(type_name);
1541 if !is_upper_camel(name) && !is_lowercase_type(name) {
1542 return None;

Callers 4

bare_call_nameMethod · 0.80
visit_bodyMethod · 0.80

Calls 7

is_upper_camelFunction · 0.85
is_lowercase_typeFunction · 0.85
is_prefixedFunction · 0.85
mapMethod · 0.80
is_commentFunction · 0.70
textMethod · 0.65
walkMethod · 0.45

Tested by

no test coverage detected