Ranges:
You may remember from some other thread, that apparently ranges were initially a "range of lines to which applies some condition".
For each line we store that "Range".
The range is stored on each line. If it is not changed, then the same range is stored again.
For me, "RangeType" is used for manage the "ranges" for highlight multiline tokens (or other information per line). Isn't it?
In some Highlighters this ranges are now very detailed.
type
TFoo = class
// ..
end ;
deprecated
Will NOT highlight the word "deprecated", but if you take the ";" away, then it will. So after the ";" starts a new range, or the other way round, there was a range that ended at the ";".
Being in a fold able block, is also part of the range. It may not (always) be something that affects how the code in this lines is parsed, but it is an attribute that applies to those lines (and besides it is a convenient place to store it)
So anything the HL needs to store, that is needed in a later line, goes into the range.
e.g. fold info is needed at the closing line. It is carried forward. So no loo back is needed.
Why is needed to store an object per line?
Because the amount of flags and info does not fit into the 32 or 64 bits of a pointer.
But yes, it is also true to extend the storage size in the array of ranges (1 per line), so there are 128 bits.
---------------
As before: The range is stored on each line. If it is not changed, then the same range is stored again.
If it is an object, ideally we do not copy the object, but duplicate the reference. However then the object stored must be immutable. If you changed it, that would affect many lines instead of just one.
The fold base HL does introduce all that is needed to deal with such an object. And it forces all inherited HL do use that object.
and aditionally "Blocks of folding" (do we call them Ranges too?)
The entire object is called the "range" now. (Actually the range is the part of code/text to which it applies).
The tutorial only showed the basics.
The range can hold whatever is needed.
But if designed well, you must look at implications such as memory.
Look at pascal, using objects. Open the IDE, and open a handful of units. You easily have 100.000 lines or more of source. Imagine a range object for each line. that are a lot of objects.
In fact, even with 1 million lines, the IDE only need approx 2000 objects In rare cases I have seen 4000.
-----------------------------
If you use the fold ID to point to an object, then you need to manage this your same.
You either get one per line, or must organize to re-use them. Well you get one for each fold-opening line, but worst case that is every line)
BTW: Those ID, are stored as part of the range-object.