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

Method misparsed_generic_call

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

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

Tested by

no test coverage detected