Using analyzer_plugin's how write a deletion for N elements in a NodeList?

45 views
Skip to first unread message

dark...@gmail.com

unread,
Apr 22, 2025, 6:36:52 PMApr 22
to Dart Analyzer Discussion
Hello!

Given an `import  ... show a,b,c', I'm trying to produce code that delete possibly two or more identifiers from the `show` list.

The thing is, dealing with commas is a bit tedious.

There's `RangeFactory.nodeInList` to help with obtaining the range for an item and its surroundings comma.
But unfortunately if we do:
for (final node in nodes) {
builder.addDeletion(range.nodeInList(list, node));
}

This ends-up producing a ConflictingEditException if two deleted elements are siblings.
I assume this happens because they are both trying to delete the same newline or comma.


Is there a solution for this, or do I have to deal with merging the SourceRanges myself?

Brian Wilkerson

unread,
Apr 25, 2025, 5:09:50 PMApr 25
to analyzer...@dartlang.org
I think `RangeFactory.argumentRange` will do what you're looking for.

--
You received this message because you are subscribed to the Google Groups "Dart Analyzer Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to analyzer-discu...@dartlang.org.
To view this discussion visit https://groups.google.com/a/dartlang.org/d/msgid/analyzer-discuss/444ed5cf-da80-4805-8d1e-8d4c86749deen%40dartlang.org.

dark...@gmail.com

unread,
Apr 25, 2025, 5:13:34 PMApr 25
to Dart Analyzer Discussion, brianwilkerson

Not quite, as:
- I don't have an ArgumentList, just a NodeList
- The elements removed aren't necessarily sibling. In `a,b,c` we may remove a/c and keep b.


I ended up building my own logic. But I assume that's something existing quick-fixes are doing already somehow.
Reply all
Reply to author
Forward
0 new messages