use std::path::Path;
use anyhow::Result;
use crate::graph::schema::{EdgeType, NodeType};
use crate::graph::Store;
use super::placeholder;
pub fn resolve_impl_trait_edges(store: &Store) -> Result<()> {
placeholder::resolve_placeholder_edges(store, &EdgeType::ImplementsTrait, &[NodeType::Trait])
}
pub fn map_traits(store: &Store, root: &Path) -> Result<()> {
#[cfg(feature = "ra")]
{
map_traits_ra(store, root)?;
}
#[cfg(not(feature = "ra"))]
{
let _ = (store, root);
}
Ok(())
}
#[cfg(feature = "ra")]
fn map_traits_ra(store: &Store, root: &Path) -> Result<()> {
let _ = store;
let _host = ra_ap_ide::AnalysisHost::default();
let _ = root
.canonicalize()
.map_err(|e| anyhow::anyhow!("root path: {e}"))?;
Ok(())
}
#[cfg(test)]
mod tests {
use crate::graph::query::Query;
use crate::graph::schema::{EdgeType, NodeId, NodeType};
use crate::graph::Store;
use super::resolve_impl_trait_edges;
#[test]
fn resolve_impl_trait_edges_resolves_same_file_placeholder() {
let store = Store::new_memory().unwrap();
let path = "src/lib.rs";
let trait_id = NodeId::new(format!("{path}#10:1"));
store
.put_node(&trait_id, &NodeType::Trait, Some("Draw"))
.unwrap();
let impl_id = NodeId::new(format!("{path}#15:1"));
store
.put_node(&impl_id, &NodeType::Impl, Some("Point"))
.unwrap();
let placeholder = NodeId::new(format!("{path}::Draw"));
store
.put_edge(&impl_id, &placeholder, &EdgeType::ImplementsTrait)
.unwrap();
resolve_impl_trait_edges(&store).unwrap();
let edges = Query::all_edges(&store).unwrap();
assert_eq!(edges.rows.len(), 1);
let to_str = edges.rows[0][1].to_string().trim_matches('"').to_string();
assert!(
to_str.contains('#'),
"edge should point to real trait id (path#line:col), got {to_str}"
);
assert_eq!(to_str, format!("{path}#10:1"));
}
}