Skip to content

Commit c00f2d8

Browse files
authored
Add Diff language (#19129)
1 parent 973143f commit c00f2d8

File tree

8 files changed

+56
-0
lines changed

8 files changed

+56
-0
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ tree-sitter-go = "0.23"
449449
tree-sitter-go-mod = { git = "https://github.com/zed-industries/tree-sitter-go-mod", rev = "a9aea5e358cde4d0f8ff20b7bc4fa311e359c7ca", package = "tree-sitter-gomod" }
450450
tree-sitter-gowork = { git = "https://github.com/zed-industries/tree-sitter-go-work", rev = "acb0617bf7f4fda02c6217676cc64acb89536dc7" }
451451
tree-sitter-heex = { git = "https://github.com/zed-industries/tree-sitter-heex", rev = "1dd45142fbb05562e35b2040c6129c9bca346592" }
452+
tree-sitter-diff = "0.1.0"
452453
tree-sitter-html = "0.20"
453454
tree-sitter-jsdoc = "0.23"
454455
tree-sitter-json = "0.23"

assets/settings/default.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,10 @@
850850
"Dart": {
851851
"tab_size": 2
852852
},
853+
"Diff": {
854+
"remove_trailing_whitespace_on_save": false,
855+
"ensure_final_newline_on_save": false
856+
},
853857
"Elixir": {
854858
"language_servers": ["elixir-ls", "!next-ls", "!lexical", "..."]
855859
},

crates/languages/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ load-grammars = [
1515
"tree-sitter-c",
1616
"tree-sitter-cpp",
1717
"tree-sitter-css",
18+
"tree-sitter-diff",
1819
"tree-sitter-go",
1920
"tree-sitter-go-mod",
2021
"tree-sitter-gowork",
@@ -59,6 +60,7 @@ tree-sitter-bash = { workspace = true, optional = true }
5960
tree-sitter-c = { workspace = true, optional = true }
6061
tree-sitter-cpp = { workspace = true, optional = true }
6162
tree-sitter-css = { workspace = true, optional = true }
63+
tree-sitter-diff = { workspace = true, optional = true }
6264
tree-sitter-go = { workspace = true, optional = true }
6365
tree-sitter-go-mod = { workspace = true, optional = true }
6466
tree-sitter-gowork = { workspace = true, optional = true }

crates/languages/src/diff/config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name = "Diff"
2+
grammar = "diff"
3+
path_suffixes = ["diff", "patch"]
4+
brackets = []
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
(addition)
3+
(new_file)
4+
] @diff.plus
5+
6+
[
7+
(deletion)
8+
(old_file)
9+
] @diff.minus
10+
11+
(commit) @constant
12+
13+
(location) @attribute
14+
15+
(command) @function

crates/languages/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub fn init(languages: Arc<LanguageRegistry>, node_runtime: NodeRuntime, cx: &mu
3737
("c", tree_sitter_c::LANGUAGE),
3838
("cpp", tree_sitter_cpp::LANGUAGE),
3939
("css", tree_sitter_css::LANGUAGE),
40+
("diff", tree_sitter_diff::LANGUAGE),
4041
("go", tree_sitter_go::LANGUAGE),
4142
("gomod", tree_sitter_go_mod::LANGUAGE),
4243
("gowork", tree_sitter_gowork::LANGUAGE),
@@ -105,6 +106,7 @@ pub fn init(languages: Arc<LanguageRegistry>, node_runtime: NodeRuntime, cx: &mu
105106
"css",
106107
vec![Arc::new(css::CssLspAdapter::new(node_runtime.clone())),]
107108
);
109+
language!("diff");
108110
language!("go", vec![Arc::new(go::GoLspAdapter)], GoContextProvider);
109111
language!("gomod", vec![Arc::new(go::GoLspAdapter)], GoContextProvider);
110112
language!(

docs/src/languages/diff.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Diff
2+
3+
Diff support is available natively in Zed.
4+
5+
- Tree Sitter: [zed-industries/the-mikedavis/tree-sitter-diff](https://github.com/the-mikedavis/tree-sitter-diff)
6+
7+
## Configuration
8+
9+
Zed will not attempt to format diff files and has [`remove_trailing_whitespace_on_save`](https://zed.dev/docs/configuring-zed#remove-trailing-whitespace-on-save) and [`ensure-final-newline-on-save`](https://zed.dev/docs/configuring-zed#ensure-final-newline-on-save) set to false.
10+
11+
Zed will automatically recognize files with `patch` and `diff` extensions as Diff files. To recognize other extensions, add them to `file_types` in your Zed settings.json:
12+
13+
```json
14+
"file_types": {
15+
"Diff": ["dif"]
16+
},
17+
```

0 commit comments

Comments
 (0)