KDAB / knut

Knut is an automation tool for code transformation using scripts.
Other
5 stars 8 forks source link

Refactor the text range/mark API #67

Open narnaud opened 1 week ago

narnaud commented 1 week ago

This is related to #54 , we currently have 4 different classes to handle position in text:

I would like to reduce to 3 different classes:

Cursor is a better term and more explicit, and I don't think we need the non-document aware version:

narnaud commented 1 week ago

@LeonMatthesKDAB What do you think? would it make sense?

LeonMatthesKDAB commented 1 week ago

API-wise this sounds good, although I don't know if there really is a need to rename Mark to Cursor. Just removing TextRange and TextLocation is probably good enough.

Before refactoring this, we should also check how many TextRange and TextLocation instances are actually used in Knut. Mark and RangeMark have a slightly higher impact on performance, as they listen to all changes in a document and update their position. I doubt it will be an issue, but maybe we can benchmark some of our scripts to see whether there is a noticeable difference.

narnaud commented 1 week ago

TextLocation is only used by Code::references, so no problem here.

`TextRange it's a bit more complex:

Creation shouldn't be a problem in term of performances (there's a shared_ptr + a connect, but it's not really that big). I don't think updates will be noticeable either... we could try and benchmark.