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

Function extract_ts_like_imports

crates/devsql/src/providers/imports.rs:166–202  ·  view source on GitHub ↗
(
    language: TsLanguageKind,
    tree: &Tree,
    lines: &LineIndex<'_>,
    source: &str,
    file_path: &str,
)

Source from the content-addressed store, hash-verified

164}
165
166fn extract_ts_like_imports(
167 language: TsLanguageKind,
168 tree: &Tree,
169 lines: &LineIndex<'_>,
170 source: &str,
171 file_path: &str,
172) -> Vec<ImportRow> {
173 let Some(query) = import_query(language) else {
174 return Vec::new();
175 };
176
177 let mut rows = Vec::new();
178 let mut cursor = QueryCursor::new();
179 let mut matches = cursor.matches(query, tree.root_node(), source.as_bytes());
180
181 while {
182 matches.advance();
183 matches.get().is_some()
184 } {
185 let matched = matches.get().unwrap();
186 for capture in matched.captures {
187 let node = capture.node;
188 let capture_name = &query.capture_names()[capture.index as usize];
189 match node.kind() {
190 "import_statement" if capture_name.starts_with("import") => {
191 parse_ts_import_statement(node, source, lines, file_path, &mut rows);
192 }
193 "export_statement" if capture_name.starts_with("export") => {
194 parse_ts_export_statement(node, source, lines, file_path, &mut rows);
195 }
196 _ => {}
197 }
198 }
199 }
200
201 rows
202}
203
204fn parse_ts_import_statement(
205 node: Node,

Callers 1

Calls 4

import_queryFunction · 0.85
matchesMethod · 0.80

Tested by

no test coverage detected