Skip to content

Commit 8e72138

Browse files
Don't discard nodes with non adjacent error siblings
1 parent 06e973b commit 8e72138

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
languageId: typescriptreact
2+
command:
3+
version: 7
4+
spokenForm: change pair
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: surroundingPair, delimiter: any}
12+
usePrePhraseSnapshot: false
13+
initialState:
14+
documentContents: |
15+
<div bbb={() => null}>hello &</div>
16+
selections:
17+
- anchor: {line: 0, character: 14}
18+
active: {line: 0, character: 14}
19+
marks: {}
20+
finalState:
21+
documentContents: |
22+
<div bbb=>hello &</div>
23+
selections:
24+
- anchor: {line: 0, character: 9}
25+
active: {line: 0, character: 9}

packages/cursorless-engine/src/languages/TreeSitterQuery/isContainedInErrorNode.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,24 @@ import type { SyntaxNode } from "web-tree-sitter";
66
* @returns True if the given node is contained in an error node
77
*/
88
export function isContainedInErrorNode(node: SyntaxNode) {
9-
let currentNode: SyntaxNode | null = node;
9+
if (node.hasError) {
10+
return true;
11+
}
12+
13+
let currentNode: SyntaxNode | null = node.parent;
1014

1115
while (currentNode != null) {
16+
// Ancestral node has errors, but it was not siblings to the previous node
17+
// that caused the problem. We don't want to discard a node when a sibling
18+
// that isn't adjacent is erroring.
1219
if (currentNode.hasError) {
20+
return false;
21+
}
22+
// A adjacent sibling node was causing the problem. ie we are right next to the error node.
23+
if (
24+
currentNode.previousSibling?.isError ||
25+
currentNode.nextSibling?.isError
26+
) {
1327
return true;
1428
}
1529
currentNode = currentNode.parent;

0 commit comments

Comments
 (0)