(conn: &Connection, repo_path: &Path)
| 83 | |
| 84 | #[cfg(feature = "tree-sitter-ast")] |
| 85 | fn load_with_tree_sitter(conn: &Connection, repo_path: &Path) -> Result<()> { |
| 86 | ensure_table(conn)?; |
| 87 | let files = walk_source_files(repo_path); |
| 88 | |
| 89 | conn.execute_batch("BEGIN")?; |
| 90 | let mut insert_stmt = conn.prepare(INSERT_SYMBOL_SQL)?; |
| 91 | let mut parser = TsParser::new(); |
| 92 | let mut next_id: i64 = 1; |
| 93 | |
| 94 | for file_info in &files { |
| 95 | if file_info.size > MAX_FILE_SIZE { |
| 96 | continue; |
| 97 | } |
| 98 | let language = detect_language(&file_info.extension); |
| 99 | let abs_path = repo_path.join(&file_info.path); |
| 100 | let Ok(content) = std::fs::read_to_string(&abs_path) else { |
| 101 | continue; |
| 102 | }; |
| 103 | let line_index = LineIndex::new(&content); |
| 104 | let mut rows = Vec::new(); |
| 105 | |
| 106 | if let Some(lang_kind) = TsLanguageKind::from_name(language) { |
| 107 | if let Some(tree) = parser.parse(language, &content) { |
| 108 | rows = extract_symbols_from_tree( |
| 109 | lang_kind, |
| 110 | &tree, |
| 111 | &line_index, |
| 112 | &content, |
| 113 | &file_info.path, |
| 114 | language, |
| 115 | &mut next_id, |
| 116 | ); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | if rows.is_empty() { |
| 121 | rows = extract_symbols_with_regex(language, &content, &file_info.path, language, &mut next_id); |
| 122 | } |
| 123 | |
| 124 | for row in rows { |
| 125 | insert_symbol(&mut insert_stmt, &row)?; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | drop(insert_stmt); |
| 130 | conn.execute_batch("COMMIT")?; |
| 131 | create_indexes(conn)?; |
| 132 | Ok(()) |
| 133 | } |
| 134 | |
| 135 | #[cfg(not(feature = "tree-sitter-ast"))] |
| 136 | fn load_with_regex(conn: &Connection, repo_path: &Path) -> Result<()> { |
no test coverage detected