pub mod csharp;
pub mod go_lang;
pub mod java;
pub mod python;
pub mod rust_lang;
pub mod typescript;
use anyhow::Result;
use std::collections::HashMap;
use tree_sitter::Language;
use crate::core::graph::Edge;
use crate::core::parser::SupportedLanguage;
pub trait LanguagePlugin: Send + Sync {
fn language(&self) -> SupportedLanguage;
fn extensions(&self) -> &[&str];
fn ts_language(&self) -> Language;
fn symbol_query_source(&self) -> &str;
fn edge_query_source(&self) -> &str;
fn infer_symbol_kind(&self, node_kind: &str) -> &str;
fn scope_node_types(&self) -> &[&str];
fn class_body_node_types(&self) -> &[&str];
fn class_decl_node_types(&self) -> &[&str];
fn extract_metadata(
&self,
node: &tree_sitter::Node,
source: &str,
kind: &str,
) -> Result<String>;
fn extract_edge(
&self,
pattern_index: usize,
captures: &HashMap<String, (String, u32)>,
file_path: &str,
enclosing_scope_id: Option<&str>,
) -> Vec<Edge>;
fn extract_docstring(&self, node: &tree_sitter::Node, source: &str) -> Option<String> {
let prev = node.prev_sibling()?;
if prev.kind() == "comment" {
let text = prev.utf8_text(source.as_bytes()).ok()?;
Some(text.trim().to_string())
} else {
None
}
}
fn generic_name_stopwords(&self) -> &[&str] {
&[]
}
}
pub fn resolve_scope_id(enclosing_scope_id: Option<&str>, file_path: &str, kind: &str) -> String {
enclosing_scope_id
.map(|s| s.to_string())
.unwrap_or_else(|| format!("{file_path}::__module__::{kind}"))
}
pub fn make_edge(
from_id: impl Into<String>,
to_id: impl Into<String>,
kind: &str,
file_path: &str,
line: u32,
) -> Edge {
Edge {
from_id: from_id.into(),
to_id: to_id.into(),
kind: kind.to_string(),
file_path: file_path.to_string(),
line: Some(line),
}
}
pub fn stopwords_for_language(language: &str) -> &'static [&'static str] {
match language {
"typescript" => typescript::TypeScriptPlugin.generic_name_stopwords(),
"csharp" => csharp::CSharpPlugin.generic_name_stopwords(),
"python" => python::PythonPlugin.generic_name_stopwords(),
"rust" => rust_lang::RustPlugin.generic_name_stopwords(),
"go" => go_lang::GoPlugin.generic_name_stopwords(),
"java" => java::JavaPlugin.generic_name_stopwords(),
_ => &[],
}
}