first pass of merging in warp (doesn't build)
This commit is contained in:
+34
-14
@@ -1,15 +1,14 @@
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::HashMap,
|
||||
path::Path,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use arborium::tree_sitter::{Language as ParserGrammar, Query};
|
||||
use galaxy_editor::content::text::IndentUnit;
|
||||
use lazy_static::lazy_static;
|
||||
use rust_embed::RustEmbed;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use galaxy_util::standardized_path::StandardizedPath;
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "grammars"]
|
||||
@@ -19,7 +18,7 @@ lazy_static! {
|
||||
static ref LANGUAGE_REGISTRY: LanguageRegistry = LanguageRegistry::new();
|
||||
}
|
||||
|
||||
pub const SUPPORTED_LANGUAGES: [&str; 32] = [
|
||||
pub const SUPPORTED_LANGUAGES: [&str; 34] = [
|
||||
"rust",
|
||||
"golang",
|
||||
"yaml",
|
||||
@@ -36,6 +35,7 @@ pub const SUPPORTED_LANGUAGES: [&str; 32] = [
|
||||
"css",
|
||||
"c",
|
||||
"json",
|
||||
"jq",
|
||||
"hcl",
|
||||
"lua",
|
||||
"ruby",
|
||||
@@ -52,6 +52,7 @@ pub const SUPPORTED_LANGUAGES: [&str; 32] = [
|
||||
"xml",
|
||||
"vue",
|
||||
"dockerfile",
|
||||
"nix",
|
||||
];
|
||||
|
||||
/// Registry that holds all of the supported languages.
|
||||
@@ -85,6 +86,19 @@ impl LanguageRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
/// Find the corresponding language entry by a standardized filename.
|
||||
pub fn language_by_filename(path: &StandardizedPath) -> Option<Arc<Language>> {
|
||||
language_by_filename_parts(path.file_name(), path.extension())
|
||||
}
|
||||
|
||||
/// Find the corresponding language entry by a local filesystem filename.
|
||||
pub fn language_by_local_filename(path: &Path) -> Option<Arc<Language>> {
|
||||
language_by_filename_parts(
|
||||
path.file_name().and_then(|file_name| file_name.to_str()),
|
||||
path.extension().and_then(|extension| extension.to_str()),
|
||||
)
|
||||
}
|
||||
|
||||
/// Normalizes common markdown language aliases to their internal names.
|
||||
/// For example, "go" -> "golang", "bash" -> "shell", etc.
|
||||
fn normalize_language_name(name: &str) -> &str {
|
||||
@@ -111,10 +125,12 @@ pub fn language_by_name(name: &str) -> Option<Arc<Language>> {
|
||||
LANGUAGE_REGISTRY.language_by_name(normalized)
|
||||
}
|
||||
|
||||
/// Find the corresponding language entry by the filename.
|
||||
pub fn language_by_filename(path: &Path) -> Option<Arc<Language>> {
|
||||
fn language_by_filename_parts(
|
||||
filename: Option<&str>,
|
||||
extension: Option<&str>,
|
||||
) -> Option<Arc<Language>> {
|
||||
// First check for specific filenames that don't use extensions.
|
||||
if let Some(filename) = path.file_name().and_then(|name| name.to_str()) {
|
||||
if let Some(filename) = filename {
|
||||
match filename {
|
||||
// Bash config files
|
||||
".bashrc" | ".bash_profile" => {
|
||||
@@ -141,7 +157,7 @@ pub fn language_by_filename(path: &Path) -> Option<Arc<Language>> {
|
||||
}
|
||||
}
|
||||
|
||||
let extension = path.extension()?.to_str()?;
|
||||
let extension = extension?;
|
||||
match extension {
|
||||
"rs" => language_by_name("rust"),
|
||||
"go" => language_by_name("golang"),
|
||||
@@ -152,15 +168,17 @@ pub fn language_by_filename(path: &Path) -> Option<Arc<Language>> {
|
||||
"tsx" => language_by_name("tsx"),
|
||||
"ts" | "cts" | "mts" => language_by_name("typescript"),
|
||||
"java" | "groovy" | "gvy" | "gy" | "gsh" => language_by_name("java"),
|
||||
"cpp" | "cxx" | "cc" | "h" | "hh" | "hpp" | "hxx" | "H" => language_by_name("cpp"),
|
||||
"sh" | "zsh" | "bash" => language_by_name("shell"),
|
||||
"cpp" | "cxx" | "cc" | "h" | "hh" | "hpp" | "hxx" | "H" | "h++" => language_by_name("cpp"),
|
||||
"sh" | "zsh" | "bash" | "command" => language_by_name("shell"),
|
||||
"cs" => language_by_name("csharp"),
|
||||
"html" => language_by_name("html"),
|
||||
"html" | "htm" => language_by_name("html"),
|
||||
"css" => language_by_name("css"),
|
||||
"c" => language_by_name("c"),
|
||||
"json" => language_by_name("json"),
|
||||
"jq" => language_by_name("jq"),
|
||||
"tf" | "hcl" | "tfvars" => language_by_name("hcl"),
|
||||
"lua" => language_by_name("lua"),
|
||||
"nix" => language_by_name("nix"),
|
||||
"rb" => language_by_name("ruby"),
|
||||
"php" | "phtml" => language_by_name("php"),
|
||||
"toml" => language_by_name("toml"),
|
||||
@@ -254,8 +272,10 @@ fn get_arborium_highlight_query(lang: &str) -> Option<&str> {
|
||||
"css" => Some(arborium::lang_css::HIGHLIGHTS_QUERY),
|
||||
"c" => Some(arborium::lang_c::HIGHLIGHTS_QUERY),
|
||||
"json" => Some(arborium::lang_json::HIGHLIGHTS_QUERY),
|
||||
"jq" => Some(arborium::lang_jq::HIGHLIGHTS_QUERY),
|
||||
"hcl" => Some(arborium::lang_hcl::HIGHLIGHTS_QUERY),
|
||||
"lua" => Some(arborium::lang_lua::HIGHLIGHTS_QUERY),
|
||||
"nix" => Some(arborium::lang_nix::HIGHLIGHTS_QUERY),
|
||||
"ruby" => Some(arborium::lang_ruby::HIGHLIGHTS_QUERY),
|
||||
"php" => Some(arborium::lang_php::HIGHLIGHTS_QUERY),
|
||||
"toml" => Some(arborium::lang_toml::HIGHLIGHTS_QUERY),
|
||||
|
||||
Reference in New Issue
Block a user