style: format seluruh workspace dengan cargo fmt
Menyeragamkan format kode sesuai rustfmt (126 file). Sebelumnya lefthook pre-commit 'cargo fmt --check' akan gagal pada commit apa pun.
This commit is contained in:
@@ -304,10 +304,7 @@ impl SymbolIndex {
|
||||
continue;
|
||||
}
|
||||
|
||||
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 extractor = match ext_dispatch.get(ext) {
|
||||
Some(f) => f,
|
||||
_ => continue, // unsupported extension
|
||||
@@ -704,8 +701,8 @@ fn extract_typescript(content: &str, rel_path: &str) -> Vec<CodeSymbol> {
|
||||
if let Some(caps) = r.ts_var_export.captures(trimmed) {
|
||||
let name = caps.get(1).unwrap().as_str().to_string();
|
||||
// Only capture top-level (indentation 0) or exported
|
||||
let is_top_level = line.starts_with(|c: char| !c.is_whitespace())
|
||||
|| trimmed.starts_with("export");
|
||||
let is_top_level =
|
||||
line.starts_with(|c: char| !c.is_whitespace()) || trimmed.starts_with("export");
|
||||
if is_top_level {
|
||||
let kind = if trimmed.contains("const ") {
|
||||
SymbolKind::Constant
|
||||
@@ -963,10 +960,7 @@ fn extract_python(content: &str, rel_path: &str) -> Vec<CodeSymbol> {
|
||||
&& !trimmed.contains("==");
|
||||
if is_top_level {
|
||||
let name = trimmed.split('=').next().unwrap_or("").trim().to_string();
|
||||
if !name.is_empty()
|
||||
&& !name.starts_with('_')
|
||||
&& !name.contains(' ')
|
||||
{
|
||||
if !name.is_empty() && !name.starts_with('_') && !name.contains(' ') {
|
||||
let kind = if name.chars().all(|c| c.is_uppercase() || c == '_') {
|
||||
SymbolKind::Constant
|
||||
} else {
|
||||
@@ -1157,10 +1151,7 @@ pub fn format_symbol_listing(index: &SymbolIndex) -> String {
|
||||
std::collections::BTreeMap::new();
|
||||
for sym in syms {
|
||||
let kind_str = sym.kind.to_string();
|
||||
by_kind
|
||||
.entry(kind_str)
|
||||
.or_default()
|
||||
.push(sym.name.as_str());
|
||||
by_kind.entry(kind_str).or_default().push(sym.name.as_str());
|
||||
}
|
||||
for (kind, names) in &by_kind {
|
||||
out.push_str(&format!(" {kind}: {}\n", names.join(", ")));
|
||||
@@ -1312,7 +1303,11 @@ impl Tool for SemanticSearch {
|
||||
}
|
||||
|
||||
let total = index.len();
|
||||
info!(matched = filtered.len(), total_indexed = total, "semantic search completed");
|
||||
info!(
|
||||
matched = filtered.len(),
|
||||
total_indexed = total,
|
||||
"semantic search completed"
|
||||
);
|
||||
|
||||
let mut by_file: std::collections::BTreeMap<String, Vec<&&CodeSymbol>> =
|
||||
std::collections::BTreeMap::new();
|
||||
@@ -1350,7 +1345,11 @@ impl Tool for SemanticSearch {
|
||||
sym.line,
|
||||
sym.context.trim(),
|
||||
doc_str,
|
||||
if sym.context.trim().len() > 80 { "…" } else { "" }
|
||||
if sym.context.trim().len() > 80 {
|
||||
"…"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
));
|
||||
}
|
||||
output.push('\n');
|
||||
@@ -1574,12 +1573,7 @@ impl Tool for ListSymbols {
|
||||
for (file, file_syms) in &by_file {
|
||||
out.push_str(&format!("`{file}`:\n"));
|
||||
for sym in file_syms {
|
||||
out.push_str(&format!(
|
||||
" `{}` {} L{}\n",
|
||||
sym.kind,
|
||||
sym.name,
|
||||
sym.line,
|
||||
));
|
||||
out.push_str(&format!(" `{}` {} L{}\n", sym.kind, sym.name, sym.line,));
|
||||
}
|
||||
}
|
||||
out.push('\n');
|
||||
@@ -1633,51 +1627,82 @@ mod tests {
|
||||
fn test_extract_typescript_function_and_class() {
|
||||
let content = "function hello() {}\nexport class User {}\ninterface Person {}\n";
|
||||
let symbols = extract_typescript(content, "test.ts");
|
||||
assert!(symbols.iter().any(|s| s.name == "hello" && s.kind == SymbolKind::Function));
|
||||
assert!(symbols.iter().any(|s| s.name == "User" && s.kind == SymbolKind::Class));
|
||||
assert!(symbols.iter().any(|s| s.name == "Person" && s.kind == SymbolKind::Interface));
|
||||
assert!(symbols
|
||||
.iter()
|
||||
.any(|s| s.name == "hello" && s.kind == SymbolKind::Function));
|
||||
assert!(symbols
|
||||
.iter()
|
||||
.any(|s| s.name == "User" && s.kind == SymbolKind::Class));
|
||||
assert!(symbols
|
||||
.iter()
|
||||
.any(|s| s.name == "Person" && s.kind == SymbolKind::Interface));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_typescript_const() {
|
||||
let content = "export const API_URL = 'http://example.com';\nconst MAX_RETRIES = 3;\n";
|
||||
let symbols = extract_typescript(content, "test.ts");
|
||||
assert!(symbols.iter().any(|s| s.name == "API_URL" && s.kind == SymbolKind::Constant));
|
||||
assert!(symbols.iter().any(|s| s.name == "MAX_RETRIES" && s.kind == SymbolKind::Constant));
|
||||
assert!(symbols
|
||||
.iter()
|
||||
.any(|s| s.name == "API_URL" && s.kind == SymbolKind::Constant));
|
||||
assert!(symbols
|
||||
.iter()
|
||||
.any(|s| s.name == "MAX_RETRIES" && s.kind == SymbolKind::Constant));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_python_def_and_class() {
|
||||
let content = "class MyClass:\n def method(self):\n pass\n\ndef top_func():\n pass\n";
|
||||
let content =
|
||||
"class MyClass:\n def method(self):\n pass\n\ndef top_func():\n pass\n";
|
||||
let symbols = extract_python(content, "test.py");
|
||||
assert!(symbols.iter().any(|s| s.name == "MyClass" && s.kind == SymbolKind::Class));
|
||||
assert!(symbols.iter().any(|s| s.name == "MyClass.method" && s.kind == SymbolKind::Function));
|
||||
assert!(symbols.iter().any(|s| s.name == "top_func" && s.kind == SymbolKind::Function));
|
||||
assert!(symbols
|
||||
.iter()
|
||||
.any(|s| s.name == "MyClass" && s.kind == SymbolKind::Class));
|
||||
assert!(symbols
|
||||
.iter()
|
||||
.any(|s| s.name == "MyClass.method" && s.kind == SymbolKind::Function));
|
||||
assert!(symbols
|
||||
.iter()
|
||||
.any(|s| s.name == "top_func" && s.kind == SymbolKind::Function));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_python_variable() {
|
||||
let content = "DATABASE_URL = 'postgres://localhost'\nconfig_path = '/etc/app'\n";
|
||||
let symbols = extract_python(content, "test.py");
|
||||
assert!(symbols.iter().any(|s| s.name == "DATABASE_URL" && s.kind == SymbolKind::Constant));
|
||||
assert!(symbols.iter().any(|s| s.name == "config_path" && s.kind == SymbolKind::Variable));
|
||||
assert!(symbols
|
||||
.iter()
|
||||
.any(|s| s.name == "DATABASE_URL" && s.kind == SymbolKind::Constant));
|
||||
assert!(symbols
|
||||
.iter()
|
||||
.any(|s| s.name == "config_path" && s.kind == SymbolKind::Variable));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_go_func_and_struct() {
|
||||
let content = "func main() {}\nfunc (s *Server) Serve() {}\ntype Config struct {\n Name string\n}\n";
|
||||
let symbols = extract_go(content, "test.go");
|
||||
assert!(symbols.iter().any(|s| s.name == "main" && s.kind == SymbolKind::Function));
|
||||
assert!(symbols.iter().any(|s| s.name == "Serve" && s.kind == SymbolKind::Function));
|
||||
assert!(symbols.iter().any(|s| s.name == "Config" && s.kind == SymbolKind::Struct));
|
||||
assert!(symbols
|
||||
.iter()
|
||||
.any(|s| s.name == "main" && s.kind == SymbolKind::Function));
|
||||
assert!(symbols
|
||||
.iter()
|
||||
.any(|s| s.name == "Serve" && s.kind == SymbolKind::Function));
|
||||
assert!(symbols
|
||||
.iter()
|
||||
.any(|s| s.name == "Config" && s.kind == SymbolKind::Struct));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_go_const_and_var() {
|
||||
let content = "const VERSION = \"1.0\"\nvar DefaultPort = 8080\n";
|
||||
let symbols = extract_go(content, "test.go");
|
||||
assert!(symbols.iter().any(|s| s.name == "VERSION" && s.kind == SymbolKind::Constant));
|
||||
assert!(symbols.iter().any(|s| s.name == "DefaultPort" && s.kind == SymbolKind::Variable));
|
||||
assert!(symbols
|
||||
.iter()
|
||||
.any(|s| s.name == "VERSION" && s.kind == SymbolKind::Constant));
|
||||
assert!(symbols
|
||||
.iter()
|
||||
.any(|s| s.name == "DefaultPort" && s.kind == SymbolKind::Variable));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user