refactor: rebuild desktop app with Tauri

This commit is contained in:
leookun committed 2026-08-24 02:49:00 +08:00
1 parent a3ec2a0dfc
commit 4053a7fb20
808 files changed
+87359 -181491

No files matched your search

@@ -0,0 +1,84 @@
//! Extension and special-filename catalog for code, documentation, and configuration.
use std::path::Path;
use crate::ContentType;
pub fn detect_language(path: &Path) -> Option<&'static str> {
let extension = path.extension()?.to_str()?.to_ascii_lowercase();
Some(match extension.as_str() {
"rs" => "rust",
"py" | "pyi" | "pyw" => "python",
"js" | "jsx" | "mjs" | "cjs" => "javascript",
"ts" | "tsx" | "mts" | "cts" => "typescript",
"go" => "go",
"java" => "java",
"c" | "h" => "c",
"cc" | "cpp" | "cxx" | "hpp" | "hxx" => "cpp",
"cs" => "csharp",
"rb" => "ruby",
"php" => "php",
"swift" => "swift",
"kt" | "kts" => "kotlin",
"scala" => "scala",
"sh" | "bash" => "bash",
"lua" => "lua",
"ex" | "exs" => "elixir",
"dart" => "dart",
"sql" => "sql",
"html" | "htm" => "html",
"css" | "scss" | "less" => "css",
"json" | "json5" => "json",
"yaml" | "yml" => "yaml",
"toml" => "toml",
"md" | "markdown" | "rst" | "adoc" => "markdown",
_ => return None,
})
}
pub fn content_type_for_path(path: &Path) -> Option<ContentType> {
let name = path.file_name()?.to_str()?.to_ascii_lowercase();
if matches!(
name.as_str(),
"cargo.toml"
| "pyproject.toml"
| "package.json"
| "tsconfig.json"
| "dockerfile"
| "makefile"
| ".gitignore"
| ".sembleignore"
) {
return Some(ContentType::Config);
}
let language = detect_language(path)?;
if language == "markdown" {
Some(ContentType::Docs)
} else if matches!(language, "json" | "yaml" | "toml") {
Some(ContentType::Config)
} else {
Some(ContentType::Code)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn classifies_code_docs_and_configuration() {
assert_eq!(
content_type_for_path(Path::new("src/main.rs")),
Some(ContentType::Code)
);
assert_eq!(
content_type_for_path(Path::new("README.md")),
Some(ContentType::Docs)
);
assert_eq!(
content_type_for_path(Path::new("Cargo.toml")),
Some(ContentType::Config)
);
assert_eq!(content_type_for_path(Path::new("image.png")), None);
}
}
+7
View File
@@ -0,0 +1,7 @@
//! Language detection and Tree-sitter parser selection.
mod catalog;
mod parser;
pub use catalog::{content_type_for_path, detect_language};
pub use parser::parser_for;
+20
View File
@@ -0,0 +1,20 @@
//! Tree-sitter parser construction for bundled high-value languages.
use tree_sitter::Parser;
pub fn parser_for(language: &str) -> Option<Parser> {
let language = match language {
"rust" => tree_sitter_rust::LANGUAGE.into(),
"python" => tree_sitter_python::LANGUAGE.into(),
"javascript" => tree_sitter_javascript::LANGUAGE.into(),
"typescript" => tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into(),
"go" => tree_sitter_go::LANGUAGE.into(),
"java" => tree_sitter_java::LANGUAGE.into(),
"c" => tree_sitter_c::LANGUAGE.into(),
"cpp" => tree_sitter_cpp::LANGUAGE.into(),
_ => return None,
};
let mut parser = Parser::new();
parser.set_language(&language).ok()?;
Some(parser)
}