Do not color html tags and other "long" "bracket pairs" (#43644)
Closes https://github.com/zed-industries/zed/issues/43621 Follow-up of https://github.com/zed-industries/zed/pull/43172 Release Notes: - (Preview only) Fixed html tags incorrectly colorized
This commit is contained in:
@@ -4292,7 +4292,13 @@ impl BufferSnapshot {
|
||||
continue;
|
||||
}
|
||||
|
||||
if !pattern.rainbow_exclude {
|
||||
if !pattern.rainbow_exclude
|
||||
// Also, certain languages have "brackets" that are not brackets, e.g. tags. and such
|
||||
// bracket will match the entire tag with all text inside.
|
||||
// For now, avoid highlighting any pair that has more than single char in each bracket.
|
||||
// We need to colorize `<Element/>` bracket pairs, so cannot make this check stricter.
|
||||
&& (open_range.len() == 1 || close_range.len() == 1)
|
||||
{
|
||||
// Certain tree-sitter grammars may return more bracket pairs than needed:
|
||||
// see `test_markdown_bracket_colorization` for a set-up that returns pairs with the same start bracket and different end one.
|
||||
// Pick the pair with the shortest range in case of ambiguity.
|
||||
@@ -4321,11 +4327,11 @@ impl BufferSnapshot {
|
||||
let new_matches = tree_sitter_matches
|
||||
.into_iter()
|
||||
.map(|(open_range, close_range, pattern, syntax_layer_depth)| {
|
||||
let participates_in_coloring =
|
||||
let participates_in_colorizing =
|
||||
bracket_matches_to_color.get(&open_range).is_some_and(
|
||||
|close_range_to_color| close_range_to_color == &close_range,
|
||||
);
|
||||
let color_index = if participates_in_coloring {
|
||||
let color_index = if participates_in_colorizing {
|
||||
while let Some(&last_bracket_end) = bracket_pairs_ends.last() {
|
||||
if last_bracket_end <= open_range.start {
|
||||
bracket_pairs_ends.pop();
|
||||
|
||||
@@ -2643,42 +2643,15 @@ pub fn rust_lang() -> Arc<Language> {
|
||||
outline: Some(Cow::from(include_str!(
|
||||
"../../languages/src/rust/outline.scm"
|
||||
))),
|
||||
indents: Some(Cow::from(
|
||||
r#"
|
||||
[
|
||||
((where_clause) _ @end)
|
||||
(field_expression)
|
||||
(call_expression)
|
||||
(assignment_expression)
|
||||
(let_declaration)
|
||||
(let_chain)
|
||||
(await_expression)
|
||||
] @indent
|
||||
|
||||
(_ "[" "]" @end) @indent
|
||||
(_ "<" ">" @end) @indent
|
||||
(_ "{" "}" @end) @indent
|
||||
(_ "(" ")" @end) @indent"#,
|
||||
)),
|
||||
brackets: Some(Cow::from(
|
||||
r#"
|
||||
("(" @open ")" @close)
|
||||
("[" @open "]" @close)
|
||||
("{" @open "}" @close)
|
||||
("<" @open ">" @close)
|
||||
(closure_parameters "|" @open "|" @close)
|
||||
(("\"" @open "\"" @close) (#set! rainbow.exclude))
|
||||
(("'" @open "'" @close) (#set! rainbow.exclude))"#,
|
||||
)),
|
||||
text_objects: Some(Cow::from(
|
||||
r#"
|
||||
(function_item
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}" )) @function.around
|
||||
"#,
|
||||
)),
|
||||
indents: Some(Cow::from(include_str!(
|
||||
"../../languages/src/rust/indents.scm"
|
||||
))),
|
||||
brackets: Some(Cow::from(include_str!(
|
||||
"../../languages/src/rust/brackets.scm"
|
||||
))),
|
||||
text_objects: Some(Cow::from(include_str!(
|
||||
"../../languages/src/rust/textobjects.scm"
|
||||
))),
|
||||
..LanguageQueries::default()
|
||||
})
|
||||
.expect("Could not parse queries");
|
||||
@@ -2697,7 +2670,7 @@ pub fn markdown_lang() -> Arc<Language> {
|
||||
path_suffixes: vec!["md".into()],
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
..LanguageConfig::default()
|
||||
},
|
||||
Some(tree_sitter_md::LANGUAGE.into()),
|
||||
)
|
||||
@@ -2708,7 +2681,7 @@ pub fn markdown_lang() -> Arc<Language> {
|
||||
injections: Some(Cow::from(include_str!(
|
||||
"../../languages/src/markdown/injections.scm"
|
||||
))),
|
||||
..Default::default()
|
||||
..LanguageQueries::default()
|
||||
})
|
||||
.expect("Could not parse markdown queries");
|
||||
Arc::new(language)
|
||||
|
||||
Reference in New Issue
Block a user