Tweak HTML indents and highlights

This commit is contained in:
Max Brunsfeld 2022-08-30 17:23:09 -07:00
parent e4f5e85c3c
commit 21fb2b9bf1
5 changed files with 16 additions and 2 deletions

View file

@ -1631,6 +1631,8 @@ impl BufferSnapshot {
if capture.index == config.indent_capture_ix { if capture.index == config.indent_capture_ix {
start.get_or_insert(Point::from_ts_point(capture.node.start_position())); start.get_or_insert(Point::from_ts_point(capture.node.start_position()));
end.get_or_insert(Point::from_ts_point(capture.node.end_position())); end.get_or_insert(Point::from_ts_point(capture.node.end_position()));
} else if Some(capture.index) == config.start_capture_ix {
start = Some(Point::from_ts_point(capture.node.end_position()));
} else if Some(capture.index) == config.end_capture_ix { } else if Some(capture.index) == config.end_capture_ix {
end = Some(Point::from_ts_point(capture.node.start_position())); end = Some(Point::from_ts_point(capture.node.start_position()));
} }

View file

@ -304,6 +304,7 @@ pub struct Grammar {
struct IndentConfig { struct IndentConfig {
query: Query, query: Query,
indent_capture_ix: u32, indent_capture_ix: u32,
start_capture_ix: Option<u32>,
end_capture_ix: Option<u32>, end_capture_ix: Option<u32>,
} }
@ -661,11 +662,13 @@ impl Language {
let grammar = self.grammar_mut(); let grammar = self.grammar_mut();
let query = Query::new(grammar.ts_language, source)?; let query = Query::new(grammar.ts_language, source)?;
let mut indent_capture_ix = None; let mut indent_capture_ix = None;
let mut start_capture_ix = None;
let mut end_capture_ix = None; let mut end_capture_ix = None;
get_capture_indices( get_capture_indices(
&query, &query,
&mut [ &mut [
("indent", &mut indent_capture_ix), ("indent", &mut indent_capture_ix),
("start", &mut start_capture_ix),
("end", &mut end_capture_ix), ("end", &mut end_capture_ix),
], ],
); );
@ -673,6 +676,7 @@ impl Language {
grammar.indents_config = Some(IndentConfig { grammar.indents_config = Some(IndentConfig {
query, query,
indent_capture_ix, indent_capture_ix,
start_capture_ix,
end_capture_ix, end_capture_ix,
}); });
} }

View file

@ -1,11 +1,15 @@
(tag_name) @keyword (tag_name) @keyword
(erroneous_end_tag_name) @keyword
(doctype) @constant (doctype) @constant
(attribute_name) @property (attribute_name) @property
(attribute_value) @string (attribute_value) @string
(comment) @comment (comment) @comment
"=" @operator
[ [
"<" "<"
">" ">"
"</" "</"
"/>"
] @punctuation.bracket ] @punctuation.bracket

View file

@ -1 +1,6 @@
(tag_name) @indent (start_tag ">" @end) @indent
(self_closing_tag "/>" @end) @indent
(element
(start_tag) @start
(end_tag)? @end) @indent

View file

@ -1,4 +1,3 @@
(script_element (script_element
(raw_text) @content (raw_text) @content
(#set! "language" "javascript")) (#set! "language" "javascript"))