sniff/
symbol_graph_impl.rs1use crate::types::LocalFileSymbols;
2use std::collections::HashMap;
3
4pub(crate) struct ResolveContext<'a> {
5 importing_file: &'a str,
6 project_root: &'a str,
7 all_files: &'a HashMap<String, String>,
8 language: &'a str,
9}
10
11#[path = "symbol_graph_path_resolver.rs"]
12mod paths;
13#[path = "symbol_graph_resolver.rs"]
14mod resolver;
15#[path = "symbol_graph_rust.rs"]
16mod rust_resolver;
17#[path = "symbol_graph_rust_target.rs"]
18mod rust_target;
19
20pub use paths::normalize_path;
21
22pub struct SymbolGraph {
23 pub files: HashMap<String, LocalFileSymbols>,
24 pub project_root: String,
25}
26
27impl SymbolGraph {
28 pub fn new(project_root: &str) -> Self {
29 SymbolGraph {
30 files: HashMap::new(),
31 project_root: project_root.to_string(),
32 }
33 }
34
35 pub fn add_file(&mut self, symbols: LocalFileSymbols) {
36 self.files.insert(symbols.file_path.clone(), symbols);
37 }
38
39 fn find_definition<'a>(
40 &'a self,
41 file_symbols: &'a LocalFileSymbols,
42 symbol_name: &str,
43 owner_type: Option<&str>,
44 ) -> Option<&'a crate::types::SymbolDefinition> {
45 file_symbols.definitions.iter().find(|def| {
46 def.name == symbol_name
47 && match owner_type {
48 Some(owner) => def.owner_type.as_deref() == Some(owner),
49 None => true,
50 }
51 })
52 }
53
54 pub fn resolve_all(&mut self) {
55 self.resolve_all_impl();
56 }
57}