Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Add Diff language (#19129)

Peter Trippc00f2d884261
diff --git a/Cargo.lock b/Cargo.lock
index 61d7ee8e671..f83feb4689d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6373,6 +6373,7 @@ dependencies = [
"tree-sitter-c",
"tree-sitter-cpp",
"tree-sitter-css",
+ "tree-sitter-diff",
"tree-sitter-go",
"tree-sitter-gomod",
"tree-sitter-gowork",
@@ -12308,6 +12309,16 @@ dependencies = [
"tree-sitter-language",
]
+[[package]]
+name = "tree-sitter-diff"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dfe1e5ca280a65dfe5ba4205c1bcc84edf486464fed315db53dee6da9a335889"
+dependencies = [
+ "cc",
+ "tree-sitter-language",
+]
+
[[package]]
name = "tree-sitter-elixir"
version = "0.3.0"
diff --git a/Cargo.toml b/Cargo.toml
index 5507fc7383e..4a4ddb44244 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -449,6 +449,7 @@ tree-sitter-go = "0.23"
tree-sitter-go-mod = { git = "https://github.com/zed-industries/tree-sitter-go-mod", rev = "a9aea5e358cde4d0f8ff20b7bc4fa311e359c7ca", package = "tree-sitter-gomod" }
tree-sitter-gowork = { git = "https://github.com/zed-industries/tree-sitter-go-work", rev = "acb0617bf7f4fda02c6217676cc64acb89536dc7" }
tree-sitter-heex = { git = "https://github.com/zed-industries/tree-sitter-heex", rev = "1dd45142fbb05562e35b2040c6129c9bca346592" }
+tree-sitter-diff = "0.1.0"
tree-sitter-html = "0.20"
tree-sitter-jsdoc = "0.23"
tree-sitter-json = "0.23"
diff --git a/assets/settings/default.json b/assets/settings/default.json
index d299f05766b..f16b37ba59b 100644
--- a/assets/settings/default.json
+++ b/assets/settings/default.json
@@ -850,6 +850,10 @@
"Dart": {
"tab_size": 2
},
+ "Diff": {
+ "remove_trailing_whitespace_on_save": false,
+ "ensure_final_newline_on_save": false
+ },
"Elixir": {
"language_servers": ["elixir-ls", "!next-ls", "!lexical", "..."]
},
diff --git a/crates/languages/Cargo.toml b/crates/languages/Cargo.toml
index dc7868ea86d..33fa874ec86 100644
--- a/crates/languages/Cargo.toml
+++ b/crates/languages/Cargo.toml
@@ -15,6 +15,7 @@ load-grammars = [
"tree-sitter-c",
"tree-sitter-cpp",
"tree-sitter-css",
+ "tree-sitter-diff",
"tree-sitter-go",
"tree-sitter-go-mod",
"tree-sitter-gowork",
@@ -59,6 +60,7 @@ tree-sitter-bash = { workspace = true, optional = true }
tree-sitter-c = { workspace = true, optional = true }
tree-sitter-cpp = { workspace = true, optional = true }
tree-sitter-css = { workspace = true, optional = true }
+tree-sitter-diff = { workspace = true, optional = true }
tree-sitter-go = { workspace = true, optional = true }
tree-sitter-go-mod = { workspace = true, optional = true }
tree-sitter-gowork = { workspace = true, optional = true }
diff --git a/crates/languages/src/diff/config.toml b/crates/languages/src/diff/config.toml
new file mode 100644
index 00000000000..e8cc71c9364
--- /dev/null
+++ b/crates/languages/src/diff/config.toml
@@ -0,0 +1,4 @@
+name = "Diff"
+grammar = "diff"
+path_suffixes = ["diff", "patch"]
+brackets = []
diff --git a/crates/languages/src/diff/highlights.scm b/crates/languages/src/diff/highlights.scm
new file mode 100644
index 00000000000..d8e600882c2
--- /dev/null
+++ b/crates/languages/src/diff/highlights.scm
@@ -0,0 +1,15 @@
+[
+ (addition)
+ (new_file)
+] @diff.plus
+
+[
+ (deletion)
+ (old_file)
+] @diff.minus
+
+(commit) @constant
+
+(location) @attribute
+
+(command) @function
diff --git a/crates/languages/src/lib.rs b/crates/languages/src/lib.rs
index 374b32c0ac3..03c4735d6d6 100644
--- a/crates/languages/src/lib.rs
+++ b/crates/languages/src/lib.rs
@@ -37,6 +37,7 @@ pub fn init(languages: Arc<LanguageRegistry>, node_runtime: NodeRuntime, cx: &mu
("c", tree_sitter_c::LANGUAGE),
("cpp", tree_sitter_cpp::LANGUAGE),
("css", tree_sitter_css::LANGUAGE),
+ ("diff", tree_sitter_diff::LANGUAGE),
("go", tree_sitter_go::LANGUAGE),
("gomod", tree_sitter_go_mod::LANGUAGE),
("gowork", tree_sitter_gowork::LANGUAGE),
@@ -105,6 +106,7 @@ pub fn init(languages: Arc<LanguageRegistry>, node_runtime: NodeRuntime, cx: &mu
"css",
vec![Arc::new(css::CssLspAdapter::new(node_runtime.clone())),]
);
+ language!("diff");
language!("go", vec![Arc::new(go::GoLspAdapter)], GoContextProvider);
language!("gomod", vec![Arc::new(go::GoLspAdapter)], GoContextProvider);
language!(
diff --git a/docs/src/languages/diff.md b/docs/src/languages/diff.md
new file mode 100644
index 00000000000..2c8db980dd8
--- /dev/null
+++ b/docs/src/languages/diff.md
@@ -0,0 +1,17 @@
+# Diff
+
+Diff support is available natively in Zed.
+
+- Tree Sitter: [zed-industries/the-mikedavis/tree-sitter-diff](https://github.com/the-mikedavis/tree-sitter-diff)
+
+## Configuration
+
+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.
+
+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:
+
+```json
+ "file_types": {
+ "Diff": ["dif"]
+ },
+```