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

Method misparsed_generic_call

codegraph-kernel/src/dart.rs:1492–1559  ·  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

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