MCPcopy Create free account
hub / github.com/concensure/Semantic / parse

Method parse

parser/src/lib.rs:93–146  ·  view source on GitHub ↗
(&mut self, path: &str, content: &str)

Source from the content-addressed store, hash-verified

91 }
92
93 pub fn parse(&mut self, path: &str, content: &str) -> Result<ParsedFile> {
94 let lang = SupportedLanguage::from_path(path)
95 .ok_or_else(|| anyhow!("unsupported language for file: {path}"))?;
96 #[cfg(feature = "rust-support")]
97 if lang == SupportedLanguage::Rust {
98 return semantic_rust::parse_to_engine(path, content);
99 }
100
101 self.parser
102 .set_language(&lang.grammar())
103 .context("failed to set tree-sitter language")?;
104
105 let cache_key = format!("{path}:{}", checksum(content));
106 let tree = if let Some(cached) = self.cache.get(&cache_key) {
107 cached
108 } else {
109 let parsed = self
110 .parser
111 .parse(content, None)
112 .ok_or_else(|| anyhow!("failed to parse file: {path}"))?;
113 self.cache.set(cache_key, parsed.clone());
114 parsed
115 };
116
117 let root = tree.root_node();
118 let mut symbols = Vec::new();
119 let mut dependencies = Vec::new();
120 let mut logic_nodes = Vec::new();
121 let import_targets = collect_import_targets(root, content, path);
122 collect_nodes(
123 root,
124 content,
125 path,
126 lang.name(),
127 &mut symbols,
128 &mut dependencies,
129 &mut logic_nodes,
130 &import_targets,
131 );
132 let (control_flow_edges, data_flow_edges, logic_clusters) =
133 build_graph_artifacts(&logic_nodes, content);
134 annotate_local_dependency_targets(path, &symbols, &mut dependencies);
135
136 Ok(ParsedFile {
137 file: path.to_string(),
138 language: lang.name().to_string(),
139 symbols,
140 dependencies,
141 logic_nodes,
142 control_flow_edges,
143 data_flow_edges,
144 logic_clusters,
145 })
146 }
147}
148
149fn checksum(content: &str) -> String {

Callers 10

mainFunction · 0.45
parses_python_functionFunction · 0.45
index_file_internalMethod · 0.45
validate_patchMethod · 0.45
mainFunction · 0.45
load_configFunction · 0.45

Calls 9

collect_import_targetsFunction · 0.85
collect_nodesFunction · 0.85
build_graph_artifactsFunction · 0.85
grammarMethod · 0.80
getMethod · 0.80
setMethod · 0.80
nameMethod · 0.80
parse_to_engineFunction · 0.50