Marker decorations that add style classes to the actual text nodes?


The ctags based syntax-highlighting makes a lot of spans with style classes for all the text and it would be suuuper nice to be able to do that programmatically. The error highlightings I’ve seen suffer a bit from being just the highlight divs separate from actual text. I also have the use case of create semantic highlighting for Scala, but that is just impossible using just the highlight decorations as is today. I want to decorate the actual text itself.

Is this really super hard to support?


You might be interested in these approaches:


Thanks for the pointers!

Hm, I’m trying to understand those approaches. It just feels that Grammar’s interface isn’t really supporting my use case. For semantical highlights it might be worth trying out, but for something like error highlights or “mark implicits”, it just feels weird. Errors and implicits would really benefit from being markers I believe - you would like to click them and get more info and stuff. But the decoration of markers using only layers and not being able to style the text seems really limiting.


The word Grammar scares me away too. This is not at all about grammar. Errors and semantical highlighting is typically depend on external libraries and compiled code and can in no way be derived only by a CFG and the textbuffer itself. So using “Grammar” to implement semantical highlighting from an external sever seems like a mad hack that will likely break in time?

Thinking about it I can’t see how Grammar could support semantical highlights for Scala. The interface just takes lines of text to tokenize right? And two identical lines in the same file can have different semantics depending on context.

Even if there’s a possibility to pass along some pushed state to the next line that would mean I have to reinvent everything. I already have a backend that takes an entire scala source file (along with full classpath and build environment) and gives back a tokenization of this file (in the context of the build). I would really like to be able to use this.


I understand your dilemma. As of right now though, your two options are Grammars or Decorations … each with their own strengths and weaknesses. Decorations don’t affect the actual text nodes themselves for performance reasons, I believe. But If you have some ideas on how to make that work in a performant way, I’m sure that could be a big help.


@leedohm Do you know if there’s any open feature request for making a programmatic API for text decoration? I’ve been putting my efforts of Scala semantic highlighting on hold until there is an API, but I just realized I wouldn’t get any notification if this is ever implemented…


Besides the one that already exists? Is this the kind of thing you’re looking for?


Sorry, I guess I was kindof unclear. I mean a programmatic api for tokenization. I guess this was the one I was looking for