Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions rust/rubydex-mcp/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,10 @@ fn format_ancestors(graph: &Graph, ancestors: &Ancestors) -> Vec<serde_json::Val
"kind": ancestor_decl.kind(),
}))
}
Ancestor::Partial(name_id) => {
let name_ref = graph.names().get(name_id)?;
Some(serde_json::json!({
"name": format!("{name_ref:?}"),
"kind": "Unresolved",
}))
}
Ancestor::Partial(name_id) => Some(serde_json::json!({
"name": graph.build_concatenated_name_from_name(*name_id),
"kind": "Unresolved",
})),
})
.collect()
}
Expand Down Expand Up @@ -845,6 +842,22 @@ mod tests {
assert_includes!(get_declaration(&s, "Person"), "ancestors", "Greetable");
}

#[test]
fn get_declaration_unresolved_ancestor_renders_qualified_name() {
// A superclass defined outside the indexed workspace (e.g. a gem) stays an
// unresolved ancestor. Its name must still serialize as a readable constant
// path, not the internal `Name` debug representation.
let s = server_with_source("class Dog < ActiveRecord::Base; end");
let res = get_declaration(&s, "Dog");

let unresolved = array!(res, "ancestors")
.iter()
.find(|a| a["kind"].as_str() == Some("Unresolved"))
.expect("expected an Unresolved ancestor");
let name = unresolved["name"].as_str().expect("expected 'name' to be a string");
assert_eq!(name, "ActiveRecord::Base");
}

#[test]
fn get_declaration_constant() {
let s = server_with_source(
Expand Down
6 changes: 4 additions & 2 deletions rust/rubydex/src/stats/orphan_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ impl Graph {
/// Falls back to `nesting` for enclosing scope context when there is no explicit parent scope.
///
/// Note: this produces a concatenated name by piecing together name parts, not a properly
/// resolved qualified name.
pub(crate) fn build_concatenated_name_from_name(&self, name_id: NameId) -> String {
/// resolved qualified name. This is the best available rendering for names that never
/// resolve to a declaration -- e.g. an ancestor defined outside the indexed workspace.
#[must_use]
pub fn build_concatenated_name_from_name(&self, name_id: NameId) -> String {
let Some(name_ref) = self.names().get(&name_id) else {
return "<unknown>".to_string();
};
Expand Down
Loading