Add a sample markdown grammar to honor the new soft wrap override

Antonio Scandurra created

Change summary

Cargo.lock                                | 11 +++++++++++
crates/zed/Cargo.toml                     |  1 +
crates/zed/languages/markdown/config.toml |  8 ++++++++
crates/zed/src/language.rs                | 12 +++++++++---
4 files changed, 29 insertions(+), 3 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -5132,6 +5132,16 @@ dependencies = [
  "regex",
 ]
 
+[[package]]
+name = "tree-sitter-markdown"
+version = "0.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c7c1cfe0396b0e500cc99067bcd2d48720eb08a077e2690194f0c3a3d105f9a0"
+dependencies = [
+ "cc",
+ "tree-sitter",
+]
+
 [[package]]
 name = "tree-sitter-rust"
 version = "0.19.0"
@@ -5721,6 +5731,7 @@ dependencies = [
  "tiny_http",
  "toml",
  "tree-sitter",
+ "tree-sitter-markdown",
  "tree-sitter-rust",
  "unindent",
  "url",

crates/zed/Cargo.toml 🔗

@@ -85,6 +85,7 @@ time = "0.3"
 tiny_http = "0.8"
 toml = "0.5"
 tree-sitter = "0.19.5"
+tree-sitter-markdown = "0.7"
 tree-sitter-rust = "0.19.0"
 url = "2.2"
 

crates/zed/languages/markdown/config.toml 🔗

@@ -0,0 +1,8 @@
+name = "Markdown"
+path_suffixes = ["md"]
+brackets = [
+    { start = "{", end = "}", close = true, newline = true },
+    { start = "[", end = "]", close = true, newline = true },
+    { start = "(", end = ")", close = true, newline = true },
+    { start = "<", end = ">", close = true, newline = true },
+]

crates/zed/src/language.rs 🔗

@@ -10,14 +10,14 @@ struct LanguageDir;
 pub fn build_language_registry() -> LanguageRegistry {
     let mut languages = LanguageRegistry::default();
     languages.add(Arc::new(rust()));
+    languages.add(Arc::new(markdown()));
     languages
 }
 
 fn rust() -> Language {
     let grammar = tree_sitter_rust::language();
-    let rust_config =
-        toml::from_slice(&LanguageDir::get("rust/config.toml").unwrap().data).unwrap();
-    Language::new(rust_config, grammar)
+    let config = toml::from_slice(&LanguageDir::get("rust/config.toml").unwrap().data).unwrap();
+    Language::new(config, grammar)
         .with_highlights_query(load_query("rust/highlights.scm").as_ref())
         .unwrap()
         .with_brackets_query(load_query("rust/brackets.scm").as_ref())
@@ -26,6 +26,12 @@ fn rust() -> Language {
         .unwrap()
 }
 
+fn markdown() -> Language {
+    let grammar = tree_sitter_markdown::language();
+    let config = toml::from_slice(&LanguageDir::get("markdown/config.toml").unwrap().data).unwrap();
+    Language::new(config, grammar)
+}
+
 fn load_query(path: &str) -> Cow<'static, str> {
     match LanguageDir::get(path).unwrap().data {
         Cow::Borrowed(s) => Cow::Borrowed(str::from_utf8(s).unwrap()),