Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ tree-sitter-md = "0.3"
tree-sitter-c-sharp = "0.23"
tree-sitter-ruby = "0.23"
tree-sitter-elixir = "0.3"
tree-sitter-java = "0.23"
tree-sitter-zig = "1.1.2"
once_cell = "1.20"
arboard = "3.4"
Expand Down
11 changes: 11 additions & 0 deletions src/command/diff/highlight/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use super::queries::*;
// Elixir uses the bundled highlight queries from tree-sitter-elixir
const ELIXIR_HIGHLIGHTS: &str = tree_sitter_elixir::HIGHLIGHTS_QUERY;

// Java uses the bundled highlight queries from tree-sitter-java
const JAVA_HIGHLIGHTS: &str = tree_sitter_java::HIGHLIGHTS_QUERY;

pub const HIGHLIGHT_NAMES: &[&str] = &[
"attribute",
"comment",
Expand Down Expand Up @@ -214,6 +217,14 @@ pub static CONFIGS: Lazy<Vec<(&'static str, LanguageConfig)>> = Lazy::new(|| {
&mut configs,
);

load_config(
tree_sitter_java::LANGUAGE.into(),
"java",
JAVA_HIGHLIGHTS,
"java",
&mut configs,
);

load_config(
tree_sitter_zig::LANGUAGE.into(),
"zig",
Expand Down
17 changes: 17 additions & 0 deletions src/command/diff/highlight/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ mod tests {
assert!(extensions.contains(&"json"), "JSON config should be loaded");
assert!(extensions.contains(&"ex"), "Elixir config should be loaded");
assert!(extensions.contains(&"exs"), "Elixir script config should be loaded");
assert!(extensions.contains(&"java"), "Java config should be loaded");
assert!(extensions.contains(&"zig"), "Zig config should be loaded");
}

Expand Down Expand Up @@ -303,6 +304,22 @@ end
assert!(has_highlights, "Elixir code should have syntax highlights");
}

#[test]
fn test_java_highlighting() {
let code = r#"package com.example;

public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
"#;
let result = highlight_code(code, "test.java");
assert!(!result.is_empty(), "Java highlighting should produce output");
let has_highlights = result.iter().any(|(_, h)| h.is_some());
assert!(has_highlights, "Java code should have syntax highlights");
}

#[test]
fn test_zig_highlighting() {
let code = r#"const std = @import("std");
Expand Down