Semantic tokens are used by the client to apply language-specific color information (syntax highlighting) to a file based on semantic information provided by the server. Instead of simple regex-based highlighting, semantic tokens allow for more accurate coloring of elements like classes, functions, and variables.
Tokens are composed of a token type (e.g., class, function) and zero or more token modifiers (e.g., static, async).
Predefined Token Types
Common types include:
namespace, type, class, enum, interface, struct, typeParameter, parameter, variable, property, enumMember, event, function, method, macro, keyword, modifier, comment, string, number, regexp, operator, and decorator (since 3.17.0).
Predefined Token Modifiers
Common modifiers include:
declaration, definition, readonly, static, deprecated, abstract, async, modification, documentation, and defaultLibrary.
export enum SemanticTokenTypes {
namespace = 'namespace',
type = 'type',
class = 'class',
enum = 'enum',
interface = 'interface',
struct = 'struct',
typeParameter = 'typeParameter',
parameter = 'parameter',
variable = 'variable',
property = 'property',
enumMember = 'enumMember',
event = 'event',
function = 'function',
method = 'method',
macro = 'macro',
keyword = 'keyword',
modifier = 'modifier',
comment = 'comment',
string = 'string',
number = 'number',
regexp = 'regexp',
operator = 'operator',
decorator = 'decorator' // since 3.17.0
}
export enum SemanticTokenModifiers {
declaration = 'declaration',
definition = 'definition',
readonly = 'readonly',
static = 'static',
deprecated = 'deprecated',
abstract = 'abstract',
async = 'async',
modification = 'modification',
documentation = 'documentation',
defaultLibrary = 'defaultLibrary'
}