How to mark specified variables or functions in codemirror like datastudio

Datastudio from google uses codemirror for creating custom variables.
If existed variable is selected they highlight the variable.
If you type SUM or COUNT, it is also highlighted.

So the question is, How can we do this ?
Thank you,