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

This commit is contained in:
Antonio Scandurra 2021-11-29 09:37:06 +01:00
parent 93de2bcfed
commit cc78ae14d4
4 changed files with 29 additions and 3 deletions

11
Cargo.lock generated
View File

@ -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",

View File

@ -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"

View File

@ -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 },
]

View File

@ -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()),