LSP semantic tokens
Also called: semantic highlighting, semantic token legend
Semantic tokens let a language server describe the roles of pieces of source code, such as a variable, a function or a class. The editor maps those roles to its theme. This can distinguish names that look alike to a simple text scanner but have different meanings in the program.
In total = add(2, 3), a server might identify total as a variable and add as a function. LSP encodes token positions and refers to a server-declared legend of token types and modifiers. Supported delta updates can send changes to an earlier token result, reducing repeated data. The protocol describes meaning and positions; it does not prescribe the colors shown to the reader.
- Read first
- LSP initialization
- Further reading
- Microsoft — LSP 3.18 semantic tokens