Possible to revalidate marker?


I was wondering if it is possible to revalidate a marker after it has been invalidated? I am using a cache of created markers and would like to reenable a decoration if one was found in the cache.


Can you give a scenario as to how this would work? Generally, when you create a marker you give it rules by which the marker becomes invalid. Other than creating a new marker, how would one step-by-step “revalidate” a marker?



I have a scenario where I would like to set a decoration for lines longer than some length. Using the TextBuffer.onDidStopChanging emitter I look over the contents of the buffer and find the lines that are longer the length and set a marker that highlights it. Iterating over the entire buffer and creating new markers sounds expensive and so I would like to cache them and simply turn them on and off.


I’m still not clear on how this would work …

  1. TextBuffer.onDidStopChanging event fires
  2. Event handler iterates over entire buffer adding a marker for each long line
  3. More typing happens, potentially invalidating some markers
  4. ???
  5. Some process whereby you correct a marker and then mark it valid again that is somehow simpler than just creating a new marker?


Yes, I also have onDidChange events for the markers that update a custom property pointing to the new line they are at. I use this property to check the line length and create a new marker or destroy if need be.


So, what’s the question?


The question is:

Is it possible to revalidate a marker instead of creating a new one? In other words I want to enable the decoration associated with it. Toggle it.


But if it is invalid, that means that the coordinates have changed in a way that is incompatible to the marker’s operation. So you would have to calculate what the new coordinates should be and then mark it valid. So how is that faster or easier than creating a new marker? If the coordinates haven’t changed in such a way, then the marker is valid still and does not need to be “revalidated”.

This is why I’m trying to see if there is a concrete, step-by-step example you can give me because I can’t imagine a situation where “revalidating” is faster or easier than simply creating a new marker. So, can you give an example of:

  1. How you would construct such a marker
  2. How it would become invalid
  3. How it could be “revalidated”


You could also use markers that are never marked invalid automatically:


Markers are considered valid when they are first created. Depending on the invalidation strategy you choose, certain changes to the buffer can cause a marker to become invalid, for example if the text surrounding the marker is deleted. The strategies, in order of descending fragility:

  • never: The marker is never marked as invalid. This is a good choice for markers representing selections in an editor.

Then you could just manage them all yourself.