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

Function load

crates/devsql/src/providers/imports.rs:39–92  ·  view source on GitHub ↗
(conn: &Connection, repo_path: &Path)

Source from the content-addressed store, hash-verified

37"#;
38
39pub fn load(conn: &Connection, repo_path: &Path) -> Result<()> {
40 ensure_table(conn)?;
41
42 let files = walk_source_files(repo_path);
43 conn.execute_batch("BEGIN")?;
44 let mut stmt = conn.prepare(INSERT_SQL)?;
45 let mut parser = TsParser::new();
46
47 for file in files {
48 if file.size > MAX_FILE_SIZE {
49 continue;
50 }
51
52 let language = detect_language(&file.extension);
53 let Some(lang_kind) = TsLanguageKind::from_name(language) else {
54 continue;
55 };
56
57 // Currently only TypeScript/JavaScript imports are implemented.
58 if !matches!(
59 lang_kind,
60 TsLanguageKind::TypeScript | TsLanguageKind::Tsx | TsLanguageKind::JavaScript | TsLanguageKind::Jsx
61 ) {
62 continue;
63 }
64
65 let abs_path = repo_path.join(&file.path);
66 let Ok(contents) = std::fs::read_to_string(&abs_path) else {
67 continue;
68 };
69
70 let line_index = LineIndex::new(&contents);
71 let Some(tree) = parser.parse(language, &contents) else {
72 continue;
73 };
74
75 let rows = extract_imports_from_tree(
76 lang_kind,
77 &tree,
78 &line_index,
79 &contents,
80 &file.path,
81 );
82
83 for row in rows {
84 insert_row(&mut stmt, &row)?;
85 }
86 }
87
88 drop(stmt);
89 conn.execute_batch("COMMIT")?;
90 create_indexes(conn)?;
91 Ok(())
92}
93
94fn ensure_table(conn: &Connection) -> Result<()> {
95 conn.execute_batch(CREATE_TABLE_SQL)?;

Callers

nothing calls this directly

Calls 7

walk_source_filesFunction · 0.85
detect_languageFunction · 0.85
insert_rowFunction · 0.85
parseMethod · 0.80
ensure_tableFunction · 0.70
create_indexesFunction · 0.70

Tested by

no test coverage detected