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

Method visibility_of

codegraph-kernel/src/ruby.rs:393–433  ·  view source on GitHub ↗

rubyExtractor.getVisibility — walk the previousNamedSibling chain (unbounded, through non-matching siblings); the first `call` sibling whose `method` text is private/protected/public decides; else public. Bug-for-bug: a BARE `private` line parses as identifier (invisible), and a matching call poisons every later sibling def regardless of ruby's actual arg-scoped semantics. The walk stops at the m

(&self, node: Node)

Source from the content-addressed store, hash-verified

391 /// every method walked back over every sibling before it, and a class or a
392 /// file of seven thousand methods took twelve seconds over this alone.
393 fn visibility_of(&self, node: Node) -> u8 {
394 let parent = node.parent().map_or(0, |p| p.id());
395 let start = node.start_byte();
396 // Only a method further down than the remembered one may lean on it.
397 let seen = self
398 .visibility_seen
399 .borrow()
400 .get(&parent)
401 .copied()
402 .filter(|(at, _)| *at < start);
403 let mut visibility = 1; // public
404 let mut sibling = node.prev_named_sibling();
405 while let Some(s) = sibling {
406 if let Some((at, known)) = seen {
407 if s.start_byte() <= at {
408 visibility = known;
409 break;
410 }
411 }
412 if s.kind() == "call" {
413 if let Some(method) = s.child_by_field_name("method") {
414 let decided = match self.text(method) {
415 "private" => Some(2),
416 "protected" => Some(3),
417 "public" => Some(1),
418 _ => None,
419 };
420 if let Some(decided) = decided {
421 visibility = decided;
422 break;
423 }
424 }
425 }
426 sibling = s.prev_named_sibling();
427 }
428 let mut memo = self.visibility_seen.borrow_mut();
429 if memo.get(&parent).is_none_or(|(at, _)| *at < start) {
430 memo.insert(parent, (start, visibility));
431 }
432 visibility
433 }
434
435 // --- the visitNode hook (languages/ruby.ts:19-76) ---------------------------
436

Callers 3

extract_functionMethod · 0.45
extract_methodMethod · 0.45
extract_classMethod · 0.45

Calls 3

idMethod · 0.80
getMethod · 0.65
textMethod · 0.65

Tested by

no test coverage detected