fix: don't highlight breaks in contextual (#1635)

This commit is contained in:
Myriad-Dreamin 2025-04-08 11:55:40 +08:00 committed by GitHub
parent d6bce89e68
commit 01afa463f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 14 additions and 15 deletions

View file

@ -39,7 +39,8 @@ impl<'a> DocumentHighlightWorker<'a> {
SyntaxKind::Arrow
| SyntaxKind::Params
| SyntaxKind::Return
| SyntaxKind::FuncReturn => return self.work_func(node),
| SyntaxKind::FuncReturn
| SyntaxKind::Contextual => return self.work_func(node),
_ => {}
}
node = node.parent()?;
@ -50,8 +51,17 @@ impl<'a> DocumentHighlightWorker<'a> {
let _ = self.ctx;
// find the nearest loop node
let loop_node = node_ancestors(node)
.find(|node| matches!(node.kind(), SyntaxKind::ForLoop | SyntaxKind::WhileLoop))?;
let loop_node = 'find_loop: {
for anc in node_ancestors(node) {
if matches!(anc.kind(), SyntaxKind::Contextual | SyntaxKind::Closure) {
return None;
}
if matches!(anc.kind(), SyntaxKind::ForLoop | SyntaxKind::WhileLoop) {
break 'find_loop anc;
}
}
return None;
};
// find the first key word of the loop node
let keyword = loop_node.children().find(|node| node.kind().is_keyword());

View file

@ -2,7 +2,6 @@
source: crates/tinymist-query/src/document_highlight.rs
expression: "JsonRepr::new_redacted(result, &REDACT_LOC)"
input_file: crates/tinymist-query/src/fixtures/document_highlight/base.typ
snapshot_kind: text
---
[
{

View file

@ -2,7 +2,6 @@
source: crates/tinymist-query/src/document_highlight.rs
expression: "JsonRepr::new_redacted(result, &REDACT_LOC)"
input_file: crates/tinymist-query/src/fixtures/document_highlight/nest.typ
snapshot_kind: text
---
[
{

View file

@ -2,7 +2,6 @@
source: crates/tinymist-query/src/document_highlight.rs
expression: "JsonRepr::new_redacted(result, &REDACT_LOC)"
input_file: crates/tinymist-query/src/fixtures/document_highlight/nest2.typ
snapshot_kind: text
---
[
{

View file

@ -2,13 +2,5 @@
source: crates/tinymist-query/src/document_highlight.rs
expression: "JsonRepr::new_redacted(result, &REDACT_LOC)"
input_file: crates/tinymist-query/src/fixtures/document_highlight/syntax_error.typ
snapshot_kind: text
---
[
{
"range": "0:0:0:4"
},
{
"range": "1:2:1:7"
}
]
null