Trouble understanding the gutter conceptually

Hi, as the title says I have difficulties working with the gutter, and maybe that’s because I don’t understand the new version 6 concepts in all detail.

I’m working on a code review tool and it’ll be possible to write a comment for multiple lines of code (these comments are not shown inside the editor though). My goal is to show the number of comments per piece of code in the gutter and highlight the gutter for all the lines that have comments.

Here’s what I have so far:
Screenshot 2021-02-03 at 12.01.50
There’s one comment each starting at line 2 and 4. And there are two (not eleven!) comments starting at line 1. Right now I’m simply adding a new instance of my GutterMarker subclass to the markers RangeSet with a hard-coded “1” and CM is just appending the element.

This is obviously wrong, and it’s where I’m kinda stuck. I did manage to solve it at some point and I can certainly go back to that solution.

So, what I’m actually asking is what would be an appropriate approach for this that works well with CM’s underlying concepts?

My ideas so far:

  • (This one I had implemented) Keep a list of comments in a StateField and every time it changes or something else is happening (like I want to highlight some comment related markers) I iterate over and re-process everything. But this seems wasteful.
  • Add GutterMarker instances to every single line and somehow address each one individually to change its content and style. But how to address them, I couldn’t find a way to get a list of those markers anywhere.

I also have trouble understanding how GutterMarker, Range and RangeSet relate to each other, and even a list of RangeSet that can be returned from the markers function, especially because a GutterMarker apparently can only refer to a single line, not multiple.

So, I hope you can help me out :pray:

The first option will probably work fine. If you have specific questions about ranges and rangesets, let me know.

1 Like

Thanks for the pointer, appreciate it! :slightly_smiling_face:

One thing that is a bit confusing to me is why the markers function in the gutter config can return either a RangeSet or a list of RangeSets. Why is that and what is the difference?

You may want to combine multiple sources of markers in a gutter—when you return an array it just displays the union of the sets.

1 Like