Skip to content

Commit

Permalink
adds highlight for diff, git-config, git-commit and git-rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl4rry committed May 31, 2024
1 parent f05351e commit 7507a10
Show file tree
Hide file tree
Showing 19 changed files with 250 additions and 7 deletions.
40 changes: 40 additions & 0 deletions Cargo.lock

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

20 changes: 14 additions & 6 deletions crates/ferrite-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ lang-cmake = ["ferrite-tree-sitter/lang-cmake"]
lang-comment = ["ferrite-tree-sitter/lang-comment"]
lang-cpp = ["ferrite-tree-sitter/lang-cpp"]
lang-css = ["ferrite-tree-sitter/lang-css"]
lang-diff = ["ferrite-tree-sitter/lang-diff"]
lang-fish = ["ferrite-tree-sitter/lang-fish"]
lang-fortran = ["ferrite-tree-sitter/lang-fortran"]
lang-git-commit = ["ferrite-tree-sitter/lang-git-commit"]
lang-git-config = ["ferrite-tree-sitter/lang-git-config"]
lang-glsl = ["ferrite-tree-sitter/lang-glsl"]
lang-go = ["ferrite-tree-sitter/lang-go"]
lang-html = ["ferrite-tree-sitter/lang-html"]
Expand All @@ -70,6 +73,7 @@ lang-javascript = ["ferrite-tree-sitter/lang-javascript"]
lang-json = ["ferrite-tree-sitter/lang-json"]
lang-md = ["ferrite-tree-sitter/lang-md"]
lang-python = ["ferrite-tree-sitter/lang-python"]
lang-rebase = ["ferrite-tree-sitter/lang-rebase"]
lang-ron = ["ferrite-tree-sitter/lang-ron"]
lang-rust = ["ferrite-tree-sitter/lang-rust"]
lang-toml = ["ferrite-tree-sitter/lang-toml"]
Expand All @@ -81,28 +85,32 @@ lang-zig = ["ferrite-tree-sitter/lang-zig"]
default = [
"embed-themes",
"lang-bash",
"lang-c",
"lang-c-sharp",
"lang-c",
"lang-cmake",
"lang-comment",
"lang-cpp",
"lang-css",
"lang-diff",
"lang-fish",
"lang-fortran",
"lang-git-commit",
"lang-git-config",
"lang-glsl",
"lang-go",
"lang-html",
"lang-hyprlang",
"lang-ini",
"lang-javascript",
"lang-json",
"lang-md",
"lang-python",
"lang-rebase",
"lang-ron",
"lang-rust",
"lang-toml",
"lang-typescript",
"lang-xml",
"lang-yaml",
"lang-fish",
"lang-comment",
"lang-javascript",
"lang-ron",
"lang-fortran",
"lang-zig",
]
41 changes: 41 additions & 0 deletions crates/ferrite-core/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ static LANGUAGES: Lazy<HashMap<&'static str, OnceCell<LanguageConfig>>> = Lazy::
langs.insert("typescript", OnceCell::new());
#[cfg(feature = "lang-ini")]
langs.insert("ini", OnceCell::new());
#[cfg(feature = "lang-diff")]
langs.insert("diff", OnceCell::new());
#[cfg(feature = "lang-git-config")]
langs.insert("git-config", OnceCell::new());
#[cfg(feature = "lang-git-commit")]
langs.insert("git-commit", OnceCell::new());
#[cfg(feature = "lang-rebase")]
langs.insert("git-rebase", OnceCell::new());
langs
});

Expand Down Expand Up @@ -294,6 +302,38 @@ fn get_lang_config(name: &str) -> Option<LanguageConfig> {
"",
"",
),
#[cfg(feature = "lang-diff")]
"diff" => LanguageConfig::new(
"diff",
ferrite_tree_sitter::tree_sitter_diff::language(),
include_str!("../../../queries/diff/highlights.scm"),
"",
"",
),
#[cfg(feature = "lang-git-config")]
"git-config" => LanguageConfig::new(
"git-config",
ferrite_tree_sitter::tree_sitter_git_config::language(),
include_str!("../../../queries/git-config/highlights.scm"),
"",
"",
),
#[cfg(feature = "lang-git-commit")]
"git-commit" => LanguageConfig::new(
"git-commit",
ferrite_tree_sitter::tree_sitter_gitcommit::language(),
include_str!("../../../queries/git-commit/highlights.scm"),
include_str!("../../../queries/git-commit/injections.scm"),
"",
),
#[cfg(feature = "lang-rebase")]
"git-rebase" => LanguageConfig::new(
"git-rebase",
ferrite_tree_sitter::tree_sitter_rebase::language(),
include_str!("../../../queries/git-rebase/highlights.scm"),
include_str!("../../../queries/git-rebase/injections.scm"),
"",
),
_ => return None,
})
}
Expand Down Expand Up @@ -335,6 +375,7 @@ pub fn get_language_from_path(path: impl AsRef<Path>) -> Option<&'static str> {
(Suffix(".go"), "go"),
(Suffix(".ts"), "ts"),
(Name("hyprland.conf"), "hyprlang"),
(Name("COMMIT_EDITMSG"), "git-commit"),
// cmake
(Name("CMakeLists.txt"), "cmake"),
(Suffix(".cmake"), "cmake"),
Expand Down
2 changes: 1 addition & 1 deletion crates/ferrite-core/src/palette/cmd_parser/generic_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl CommandTemplate {

pub fn usage(&self) -> String {
let mut usage = self.name.clone();
for (arg, _) in &self.args {
if let Some((arg, _)) = &self.args {
usage.push(' ');
usage.push_str(arg);
}
Expand Down
5 changes: 5 additions & 0 deletions crates/ferrite-core/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ impl Workspace {
.iter()
.filter_map(|(_, buffer)| buffer.file().map(|path| (path, buffer)))
{
let language = &buffer.language_name();
if language.starts_with("git-") && language != "git-config" {
continue;
}

let buffer_data = BufferData {
path: path.to_path_buf(),
cursor: buffer.cursor(),
Expand Down
8 changes: 8 additions & 0 deletions crates/ferrite-tree-sitter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ tree-sitter-cmake = { version = "0.2.0", optional = true }
tree-sitter-comment = { git = "https://github.com/stsewd/tree-sitter-comment", rev = "94c99a66bb5051d8321b5900aee92b76450c50ce", optional = true }
tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "a90f170f92d5d70e7c2d4183c146e61ba5f3a457", optional = true }
tree-sitter-css = { git = "https://github.com/syntacti/tree-sitter-css", rev = "397aa132b9982fcdd2d473ed69343762a557f10a", optional = true }
tree-sitter-diff = { git = "https://github.com/the-mikedavis/tree-sitter-diff", rev = "fd74c78fa88a20085dbc7bbeaba066f4d1692b63", optional = true }
tree-sitter-fish = { git = "https://github.com/ram02z/tree-sitter-fish", rev = "6675b56266b3f615fb112205b6b83a79315309c4", optional = true }
tree-sitter-fortran = { git = "https://github.com/stadelmanma/tree-sitter-fortran", rev = "f73d473e3530862dee7cbb38520f28824e7804f6", optional = true }
tree-sitter-git-config = { git = "https://github.com/the-mikedavis/tree-sitter-git-config", rev = "9c2a1b7894e6d9eedfe99805b829b4ecd871375e", optional = true }
tree-sitter-gitcommit = { git = "https://github.com/the-mikedavis/tree-sitter-git-commit", rev = "6f193a66e9aa872760823dff020960c6cedc37b3", optional = true }
tree-sitter-glsl = { git = "https://github.com/theHamsta/tree-sitter-glsl", rev = "74329feb2605deccd32b1c644af507daa6fb82f1", optional = true }
tree-sitter-go = { git = "https://github.com/tree-sitter/tree-sitter-go", rev = "64457ea6b73ef5422ed1687178d4545c3e91334a", optional = true }
tree-sitter-html = { version = "0.19.0", optional = true }
Expand All @@ -23,6 +26,7 @@ tree-sitter-javascript = { git = "https://github.com/tree-sitter/tree-sitter-jav
tree-sitter-json = { version = "0.19.0", optional = true }
tree-sitter-md = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "272e080bca0efd19a06a7f4252d746417224959e", optional = true }
tree-sitter-python = { version = "0.20.2", optional = true }
tree-sitter-rebase = { git = "https://github.com/the-mikedavis/tree-sitter-git-rebase", rev = "d8a4207ebbc47bd78bacdf48f883db58283f9fd8", optional = true }
tree-sitter-ron = { git = "https://github.com/amaanq/tree-sitter-ron", rev = "ce6086b2c9e8e71065b8129d6c2289c5f66d1879", optional = true }
tree-sitter-rust = { version = "0.20.3", optional = true }
tree-sitter-toml = { git = "https://github.com/Mathspy/tree-sitter-toml", optional = true }
Expand All @@ -39,8 +43,11 @@ lang-cmake = ["dep:tree-sitter-cmake"]
lang-comment = ["dep:tree-sitter-comment"]
lang-cpp = ["dep:tree-sitter-cpp"]
lang-css = ["dep:tree-sitter-css"]
lang-diff = ["dep:tree-sitter-diff"]
lang-fish = ["dep:tree-sitter-fish"]
lang-fortran = ["dep:tree-sitter-fortran"]
lang-git-commit = ["dep:tree-sitter-gitcommit"]
lang-git-config = ["dep:tree-sitter-git-config"]
lang-glsl = ["dep:tree-sitter-glsl"]
lang-go = ["dep:tree-sitter-go"]
lang-html = ["dep:tree-sitter-html"]
Expand All @@ -50,6 +57,7 @@ lang-javascript = ["dep:tree-sitter-javascript"]
lang-json = ["dep:tree-sitter-json"]
lang-md = ["dep:tree-sitter-md"]
lang-python = ["dep:tree-sitter-python"]
lang-rebase = ["dep:tree-sitter-rebase"]
lang-ron = ["dep:tree-sitter-ron"]
lang-rust = ["dep:tree-sitter-rust"]
lang-toml = ["dep:tree-sitter-toml"]
Expand Down
8 changes: 8 additions & 0 deletions crates/ferrite-tree-sitter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ pub use tree_sitter_comment;
pub use tree_sitter_cpp;
#[cfg(feature = "lang-css")]
pub use tree_sitter_css;
#[cfg(feature = "lang-diff")]
pub use tree_sitter_diff;
#[cfg(feature = "lang-fish")]
pub use tree_sitter_fish;
#[cfg(feature = "lang-fortran")]
pub use tree_sitter_fortran;
#[cfg(feature = "lang-git-config")]
pub use tree_sitter_git_config;
#[cfg(feature = "lang-git-commit")]
pub use tree_sitter_gitcommit;
#[cfg(feature = "lang-glsl")]
pub use tree_sitter_glsl;
#[cfg(feature = "lang-go")]
Expand All @@ -34,6 +40,8 @@ pub use tree_sitter_json;
pub use tree_sitter_md;
#[cfg(feature = "lang-python")]
pub use tree_sitter_python;
#[cfg(feature = "lang-rebase")]
pub use tree_sitter_rebase;
#[cfg(feature = "lang-ron")]
pub use tree_sitter_ron;
#[cfg(feature = "lang-rust")]
Expand Down
6 changes: 6 additions & 0 deletions queries/diff/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[(addition) (new_file)] @diff.plus
[(deletion) (old_file)] @diff.minus

(commit) @constant
(location) @attribute
(command) @markup.bold
18 changes: 18 additions & 0 deletions queries/git-commit/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(subject) @markup.heading
(path) @string.special.path
(branch) @string.special.symbol
(commit) @constant
(item) @markup.link.url
(header) @tag

(change kind: "new file" @diff.plus)
(change kind: "deleted" @diff.minus)
(change kind: "modified" @diff.delta)
(change kind: "renamed" @diff.delta.moved)

(trailer
key: (trailer_key) @variable.other.member
value: (trailer_value) @string)

[":" "=" "->" (scissors)] @punctuation.delimiter
(comment) @comment
8 changes: 8 additions & 0 deletions queries/git-commit/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(((scissors)
(message) @injection.content)
(#set! injection.include-children)
(#set! injection.language "diff"))

((rebase_command) @injection.content
(#set! injection.include-children)
(#set! injection.language "git-rebase"))
28 changes: 28 additions & 0 deletions queries/git-config/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
((section_name) @keyword.directive
(#eq? @keyword.directive "include"))

((section_header
(section_name) @keyword.directive
(subsection_name))
(#eq? @keyword.directive "includeIf"))

(section_name) @markup.heading
(variable (name) @variable.other.member)
[(true) (false)] @constant.builtin.boolean
(integer) @constant.numeric.integer

((string) @string.special.path
(#match? @string.special.path "^(~|./|/)"))

[(string) (subsection_name)] @string

[
"["
"]"
] @punctuation.bracket

["=" "\\"] @punctuation.delimiter

(escape_sequence) @constant.character.escape

(comment) @comment
36 changes: 36 additions & 0 deletions queries/git-rebase/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
; a rough translation:
; * constant.builtin - git hash
; * constant - a git label
; * keyword - command that acts on commits commits
; * function - command that acts only on labels
; * comment - discarded commentary on a command, has no effect on the rebase
; * string - text used in the rebase operation
; * operator - a 'switch' (used in fixup and merge), either -c or -C at time of writing

(((command) @keyword
(label) @constant.builtin
(message)? @comment)
(#match? @keyword "^(p|pick|r|reword|e|edit|s|squash|d|drop)$"))

(((command) @function
(label) @constant
(message)? @comment)
(#match? @function "^(l|label|t|reset|u|update-ref)$"))

((command) @keyword
(#match? @keyword "^(x|exec|b|break)$"))

(((command) @attribute
(label) @constant.builtin
(message)? @comment)
(#match? @attribute "^(f|fixup)$"))

(((command) @keyword
(label) @constant.builtin
(label) @constant
(message) @string)
(#match? @keyword "^(m|merge)$"))

(option) @operator

(comment) @comment
5 changes: 5 additions & 0 deletions queries/git-rebase/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(((command) @attribute
(message)? @injection.content)
(#match? @attribute "^(x|exec)$")
(#set! injection.language "bash")
)
Loading

0 comments on commit 7507a10

Please sign in to comment.