(conn: &Connection, repo_path: &Path)
| 37 | "#; |
| 38 | |
| 39 | pub 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 | |
| 94 | fn ensure_table(conn: &Connection) -> Result<()> { |
| 95 | conn.execute_batch(CREATE_TABLE_SQL)?; |
nothing calls this directly
no test coverage detected