feat: rag-embedding-ai-chat (#1)
Co-authored-by: Sharang Parnerkar <parnerkarsharang@gmail.com> Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
@@ -7,6 +7,12 @@ use tree_sitter::{Node, Parser};
|
||||
|
||||
pub struct JavaScriptParser;
|
||||
|
||||
impl Default for JavaScriptParser {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl JavaScriptParser {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
@@ -51,7 +57,13 @@ impl JavaScriptParser {
|
||||
|
||||
if let Some(body) = node.child_by_field_name("body") {
|
||||
self.extract_calls(
|
||||
body, source, file_path, repo_id, graph_build_id, &qualified, output,
|
||||
body,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
&qualified,
|
||||
output,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -97,7 +109,12 @@ impl JavaScriptParser {
|
||||
|
||||
if let Some(body) = node.child_by_field_name("body") {
|
||||
self.walk_children(
|
||||
body, source, file_path, repo_id, graph_build_id, Some(&qualified),
|
||||
body,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
Some(&qualified),
|
||||
output,
|
||||
);
|
||||
}
|
||||
@@ -130,7 +147,13 @@ impl JavaScriptParser {
|
||||
|
||||
if let Some(body) = node.child_by_field_name("body") {
|
||||
self.extract_calls(
|
||||
body, source, file_path, repo_id, graph_build_id, &qualified, output,
|
||||
body,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
&qualified,
|
||||
output,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -138,7 +161,13 @@ impl JavaScriptParser {
|
||||
// Arrow functions assigned to variables: const foo = () => {}
|
||||
"lexical_declaration" | "variable_declaration" => {
|
||||
self.extract_arrow_functions(
|
||||
node, source, file_path, repo_id, graph_build_id, parent_qualified, output,
|
||||
node,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
parent_qualified,
|
||||
output,
|
||||
);
|
||||
}
|
||||
"import_statement" => {
|
||||
@@ -183,7 +212,13 @@ impl JavaScriptParser {
|
||||
let mut cursor = node.walk();
|
||||
for child in node.children(&mut cursor) {
|
||||
self.walk_tree(
|
||||
child, source, file_path, repo_id, graph_build_id, parent_qualified, output,
|
||||
child,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
parent_qualified,
|
||||
output,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -217,7 +252,13 @@ impl JavaScriptParser {
|
||||
let mut cursor = node.walk();
|
||||
for child in node.children(&mut cursor) {
|
||||
self.extract_calls(
|
||||
child, source, file_path, repo_id, graph_build_id, caller_qualified, output,
|
||||
child,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
caller_qualified,
|
||||
output,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -263,7 +304,12 @@ impl JavaScriptParser {
|
||||
|
||||
if let Some(body) = value_n.child_by_field_name("body") {
|
||||
self.extract_calls(
|
||||
body, source, file_path, repo_id, graph_build_id, &qualified,
|
||||
body,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
&qualified,
|
||||
output,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,12 @@ use tree_sitter::{Node, Parser};
|
||||
|
||||
pub struct PythonParser;
|
||||
|
||||
impl Default for PythonParser {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl PythonParser {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
|
||||
@@ -57,10 +57,7 @@ impl ParserRegistry {
|
||||
repo_id: &str,
|
||||
graph_build_id: &str,
|
||||
) -> Result<Option<ParseOutput>, CoreError> {
|
||||
let ext = file_path
|
||||
.extension()
|
||||
.and_then(|e| e.to_str())
|
||||
.unwrap_or("");
|
||||
let ext = file_path.extension().and_then(|e| e.to_str()).unwrap_or("");
|
||||
|
||||
let parser_idx = match self.extension_map.get(ext) {
|
||||
Some(idx) => *idx,
|
||||
@@ -89,7 +86,15 @@ impl ParserRegistry {
|
||||
let mut combined = ParseOutput::default();
|
||||
let mut node_count: u32 = 0;
|
||||
|
||||
self.walk_directory(dir, dir, repo_id, graph_build_id, max_nodes, &mut node_count, &mut combined)?;
|
||||
self.walk_directory(
|
||||
dir,
|
||||
dir,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
max_nodes,
|
||||
&mut node_count,
|
||||
&mut combined,
|
||||
)?;
|
||||
|
||||
info!(
|
||||
nodes = combined.nodes.len(),
|
||||
@@ -162,8 +167,7 @@ impl ParserRegistry {
|
||||
Err(_) => continue, // Skip binary/unreadable files
|
||||
};
|
||||
|
||||
if let Some(output) = self.parse_file(rel_path, &source, repo_id, graph_build_id)?
|
||||
{
|
||||
if let Some(output) = self.parse_file(rel_path, &source, repo_id, graph_build_id)? {
|
||||
*node_count += output.nodes.len() as u32;
|
||||
combined.nodes.extend(output.nodes);
|
||||
combined.edges.extend(output.edges);
|
||||
|
||||
@@ -7,6 +7,12 @@ use tree_sitter::{Node, Parser};
|
||||
|
||||
pub struct RustParser;
|
||||
|
||||
impl Default for RustParser {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl RustParser {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
@@ -196,9 +202,7 @@ impl RustParser {
|
||||
id: None,
|
||||
repo_id: repo_id.to_string(),
|
||||
graph_build_id: graph_build_id.to_string(),
|
||||
source: parent_qualified
|
||||
.unwrap_or(file_path)
|
||||
.to_string(),
|
||||
source: parent_qualified.unwrap_or(file_path).to_string(),
|
||||
target: path,
|
||||
kind: CodeEdgeKind::Imports,
|
||||
file_path: file_path.to_string(),
|
||||
@@ -354,10 +358,7 @@ impl RustParser {
|
||||
|
||||
fn extract_use_path(&self, use_text: &str) -> Option<String> {
|
||||
// "use foo::bar::baz;" -> "foo::bar::baz"
|
||||
let trimmed = use_text
|
||||
.strip_prefix("use ")?
|
||||
.trim_end_matches(';')
|
||||
.trim();
|
||||
let trimmed = use_text.strip_prefix("use ")?.trim_end_matches(';').trim();
|
||||
Some(trimmed.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,12 @@ use tree_sitter::{Node, Parser};
|
||||
|
||||
pub struct TypeScriptParser;
|
||||
|
||||
impl Default for TypeScriptParser {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeScriptParser {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
@@ -49,7 +55,13 @@ impl TypeScriptParser {
|
||||
|
||||
if let Some(body) = node.child_by_field_name("body") {
|
||||
self.extract_calls(
|
||||
body, source, file_path, repo_id, graph_build_id, &qualified, output,
|
||||
body,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
&qualified,
|
||||
output,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -80,12 +92,23 @@ impl TypeScriptParser {
|
||||
|
||||
// Heritage clause (extends/implements)
|
||||
self.extract_heritage(
|
||||
&node, source, file_path, repo_id, graph_build_id, &qualified, output,
|
||||
&node,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
&qualified,
|
||||
output,
|
||||
);
|
||||
|
||||
if let Some(body) = node.child_by_field_name("body") {
|
||||
self.walk_children(
|
||||
body, source, file_path, repo_id, graph_build_id, Some(&qualified),
|
||||
body,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
Some(&qualified),
|
||||
output,
|
||||
);
|
||||
}
|
||||
@@ -143,14 +166,26 @@ impl TypeScriptParser {
|
||||
|
||||
if let Some(body) = node.child_by_field_name("body") {
|
||||
self.extract_calls(
|
||||
body, source, file_path, repo_id, graph_build_id, &qualified, output,
|
||||
body,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
&qualified,
|
||||
output,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
"lexical_declaration" | "variable_declaration" => {
|
||||
self.extract_arrow_functions(
|
||||
node, source, file_path, repo_id, graph_build_id, parent_qualified, output,
|
||||
node,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
parent_qualified,
|
||||
output,
|
||||
);
|
||||
}
|
||||
"import_statement" => {
|
||||
@@ -172,7 +207,13 @@ impl TypeScriptParser {
|
||||
}
|
||||
|
||||
self.walk_children(
|
||||
node, source, file_path, repo_id, graph_build_id, parent_qualified, output,
|
||||
node,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
parent_qualified,
|
||||
output,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -189,7 +230,13 @@ impl TypeScriptParser {
|
||||
let mut cursor = node.walk();
|
||||
for child in node.children(&mut cursor) {
|
||||
self.walk_tree(
|
||||
child, source, file_path, repo_id, graph_build_id, parent_qualified, output,
|
||||
child,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
parent_qualified,
|
||||
output,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -223,7 +270,13 @@ impl TypeScriptParser {
|
||||
let mut cursor = node.walk();
|
||||
for child in node.children(&mut cursor) {
|
||||
self.extract_calls(
|
||||
child, source, file_path, repo_id, graph_build_id, caller_qualified, output,
|
||||
child,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
caller_qualified,
|
||||
output,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -269,7 +322,12 @@ impl TypeScriptParser {
|
||||
|
||||
if let Some(body) = value_n.child_by_field_name("body") {
|
||||
self.extract_calls(
|
||||
body, source, file_path, repo_id, graph_build_id, &qualified,
|
||||
body,
|
||||
source,
|
||||
file_path,
|
||||
repo_id,
|
||||
graph_build_id,
|
||||
&qualified,
|
||||
output,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user