MCPcopy Create free account
hub / github.com/douglance/devsql / extract_symbols_from_tree

Function extract_symbols_from_tree

crates/devsql/src/providers/symbols.rs:198–267  ·  view source on GitHub ↗
(
    language: TsLanguageKind,
    tree: &Tree,
    lines: &LineIndex<'_>,
    source: &str,
    file_path: &str,
    language_label: &str,
    next_id: &mut i64,
)

Source from the content-addressed store, hash-verified

196
197#[cfg(feature = "tree-sitter-ast")]
198fn extract_symbols_from_tree(
199 language: TsLanguageKind,
200 tree: &Tree,
201 lines: &LineIndex<'_>,
202 source: &str,
203 file_path: &str,
204 language_label: &str,
205 next_id: &mut i64,
206) -> Vec<SymbolRow> {
207 let mut rows = Vec::new();
208 let mut node_to_id: HashMap<usize, i64> = HashMap::new();
209 let Some(query) = symbol_query(language) else {
210 return rows;
211 };
212
213 let mut cursor = QueryCursor::new();
214 let mut matches = cursor.matches(query, tree.root_node(), source.as_bytes());
215 while {
216 matches.advance();
217 matches.get().is_some()
218 } {
219 let m = matches.get().unwrap();
220 for capture in m.captures {
221 let capture_name = &query.capture_names()[capture.index as usize];
222 if !capture_name.ends_with(".definition") {
223 continue;
224 }
225 let mut kind_key = capture_name.split('.').next().unwrap_or("").to_string();
226 let mut node = capture.node;
227 if language == TsLanguageKind::Python && kind_key == "decorated" {
228 if let Some(inner) = decorated_target(node) {
229 kind_key = inner.kind().to_string();
230 node = inner;
231 }
232 }
233 let name = extract_name(node, source);
234 if name.is_empty() {
235 continue;
236 }
237 let kind = normalize_kind(language, &kind_key, node);
238 let line_start = (node.start_position().row + 1) as i64;
239 let line_end = lines.inclusive_line_for_end(node.end_byte()) as i64;
240 let signature = signature_text(node, source);
241 let visibility = visibility_text(language, node, source);
242 let parameters = parameters_text(language, node, source);
243 let return_type = return_type_text(language, node, source);
244 let parent_id = parent_symbol_id(node, &node_to_id);
245 let id = *next_id;
246 *next_id += 1;
247
248 node_to_id.insert(node.id(), id);
249 rows.push(SymbolRow {
250 id,
251 file_path: file_path.to_string(),
252 name,
253 kind,
254 line_start,
255 line_end,

Callers 1

load_with_tree_sitterFunction · 0.85

Calls 12

symbol_queryFunction · 0.85
decorated_targetFunction · 0.85
extract_nameFunction · 0.85
normalize_kindFunction · 0.85
signature_textFunction · 0.85
visibility_textFunction · 0.85
parameters_textFunction · 0.85
return_type_textFunction · 0.85
parent_symbol_idFunction · 0.85
matchesMethod · 0.80
is_emptyMethod · 0.80

Tested by

no test coverage detected