first pass of merging in warp (doesn't build)

This commit is contained in:
Ryan Ward
2026-07-01 16:08:58 -05:00
parent 2f64909469
commit 4770ac06b5
3662 changed files with 414574 additions and 89772 deletions
+34 -14
View File
@@ -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),
+53 -7
View File
@@ -1,6 +1,8 @@
use std::path::Path;
use crate::{language_by_filename, load_language, SUPPORTED_LANGUAGES};
use warp_util::standardized_path::StandardizedPath;
use crate::{language_by_filename, language_by_local_filename, load_language, SUPPORTED_LANGUAGES};
/// Validate that every supported language can be loaded successfully.
/// This catches invalid node types, syntax errors, and other issues in .scm query files
@@ -23,12 +25,56 @@ fn all_supported_languages_load_successfully() {
);
}
/// Both `.html` and the legacy three-character `.htm` extension should resolve to
/// the same HTML language entry. `.htm` is widely produced by static-site generators
/// and historical web tooling (DOS 8.3 filename limits) and is already treated as
/// an HTML/text file elsewhere in the codebase
/// (see `is_development_text_extension` in `crates/warp_util/src/file_type.rs`).
#[test]
fn cpp_header_extensions_resolve_to_cpp_language() {
for filename in ["header.hpp", "header.hxx", "header.H"] {
let language = language_by_filename(Path::new(filename))
.unwrap_or_else(|| panic!("expected {filename} to resolve to C++"));
assert_eq!(language.display_name(), "C++");
fn html_extensions_resolve_to_html() {
for filename in ["index.html", "index.htm"] {
let path = StandardizedPath::try_new(&format!("/tmp/{filename}"))
.expect("test path should be absolute");
let language = language_by_filename(&path)
.unwrap_or_else(|| panic!("expected {filename} to resolve to a language"));
assert_eq!(
language.display_name(),
"HTML",
"{filename} should resolve to HTML",
);
}
}
#[test]
fn local_html_extensions_resolve_to_html() {
for filename in ["index.html", "index.htm"] {
let path = Path::new(filename);
let language = language_by_local_filename(path)
.unwrap_or_else(|| panic!("expected {filename} to resolve to a language"));
assert_eq!(
language.display_name(),
"HTML",
"{filename} should resolve to HTML",
);
}
}
/// `.command` is the macOS convention for double-clickable shell scripts.
/// Make sure `language_by_filename` recognizes it as shell so the editor
/// renders syntax highlighting instead of the
/// "Language support is unavailable for this file type" footer.
#[test]
fn command_extension_resolves_to_shell() {
let path =
StandardizedPath::try_new("/tmp/script.command").expect("test path should be absolute");
let language =
language_by_filename(&path).expect("`.command` files should resolve to a language");
assert_eq!(language.display_name(), "Shell");
}
#[test]
fn local_command_extension_resolves_to_shell() {
let language = language_by_local_filename(Path::new("script.command"))
.expect("`.command` files should resolve to a language");
assert_eq!(language.display_name(), "Shell");
}