Skip to content

Don't discard nodes with non adjacent error siblings #2860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions data/fixtures/recorded/surroundingPair/changePair.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
languageId: typescriptreact
command:
version: 7
spokenForm: change pair
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: surroundingPair, delimiter: any}
usePrePhraseSnapshot: false
initialState:
documentContents: |
<div bbb={() => null}>hello &</div>
Copy link
Member Author

@AndreasArvidsson AndreasArvidsson Feb 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails on main. & is not a valid syntax in jsx. Because of this > in => was incorrectly used as a pair delimiter.
I actually ran into this in code I was working on where the & was about a hundred lines below the =>. That took some figuring out.

selections:
- anchor: {line: 0, character: 14}
active: {line: 0, character: 14}
marks: {}
finalState:
documentContents: |
<div bbb=>hello &</div>
selections:
- anchor: {line: 0, character: 9}
active: {line: 0, character: 9}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,35 @@ import type { SyntaxNode } from "web-tree-sitter";
* @returns True if the given node is contained in an error node
*/
export function isContainedInErrorNode(node: SyntaxNode) {
let currentNode: SyntaxNode | null = node;
// This node or one of it descendants is an error node
if (node.hasError) {
return true;
}

let ancestorNode: SyntaxNode | null = node.parent;

while (ancestorNode != null) {
// Ancestral node is an error node
if (ancestorNode.isError) {
return true;
}

// Ancestral node has errors, but it was not siblings to the previous node.
// We don't want to discard a node when a sibling that isn't adjacent is
// erroring.
if (ancestorNode.hasError) {
return false;
}

while (currentNode != null) {
if (currentNode.hasError) {
// A adjacent sibling node was causing the problem. ie we are right next to the error node.
if (
ancestorNode.previousSibling?.isError ||
ancestorNode.nextSibling?.isError
) {
return true;
}
currentNode = currentNode.parent;

ancestorNode = ancestorNode.parent;
}

return false;
Expand Down
Loading