Adding more detailed classnames to tokens?

Codemirror’s css classes are pretty limited, and in many cases ambiguous. This causes a lot of cross-mode theme inconsistencies and often prevents smarter highlighting. I’d like to add more detailed classes to some tokens. For example a javascript tokenizer can easily distinguish that all blah in the following are function names, distinct from variables.

function blah() {}
blah()
blah.apply()
blah.call()
```

What would be the best way to add extra classes, like `.cm-function` to these tokens? Are there external hooks for the tokenizer or parser? Do I need to create an overlay mode? A wrapping mode?

Thanks!

I don’t think you want to go down that road. What about…

let x = function() {}
let y = someFunctionReturningFunction()

… etc. To get consistent separate highlighting of variables that happen to hold a function, you’d need to do some serious type inference, and that’s too expensive to do in a highlighter. So you’d get a shaky half solution that sometimes works, which is probably worse than nothing at all.

But yes, if you really want to do that, you can write a wrapping mode.