semtok

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package semtok is the semantic-token vocabulary a classified document is written in: the LSP-standardized classes and modifiers, the lexical half of the classification (keywords, comments and literals, which need no symbol table), and the relative UTF-16 encoding the Language Server Protocol transmits them in.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(content []byte, toks []Token) []uint32

Encode encodes tokens relative to their predecessor in UTF-16 units, splitting a multi-line token per line as the encoding requires: the data array a SemanticTokens answer carries.

Types

type Class

type Class int

Class is the kind of a semantic token. Its String is the LSP token type name.

const (
	ClassNamespace Class = iota
	ClassClass
	ClassEnum
	ClassInterface
	ClassStruct
	ClassParameter
	ClassVariable
	ClassProperty
	ClassEnumMember
	ClassFunction
	ClassMethod
	ClassKeyword
	ClassComment
	ClassString
	ClassNumber
)

The classes this package emits, in legend order.

func Classes

func Classes() []Class

Classes returns every class in legend order, so a class's index in the result is the token type index an encoded token carries.

func (Class) String

func (c Class) String() string

String returns the LSP token type name of the class.

type Modifier

type Modifier uint32

Modifier is a bitset of token modifiers. Bit i is the modifier at index i of Modifiers.

const (
	ModDeclaration Modifier = 1 << iota
	ModDefinition
	ModReadonly
	ModAbstract
)

The modifiers this package emits, in legend order.

func Modifiers

func Modifiers() []Modifier

Modifiers returns every modifier in legend order.

func (Modifier) String

func (m Modifier) String() string

String returns the LSP modifier name of a single modifier bit.

type Position

type Position struct {
	Line      uint32
	Character uint32
}

Position is a zero-based line and character, the shape the LSP reports in; the character counts UTF-16 code units.

type Token

type Token struct {
	Span      source.Span
	Class     Class
	Modifiers Modifier
}

Token is one classified span of source text.

func Lexical

func Lexical(content []byte, kind source.Kind) []Token

Lexical classifies keywords, comments and literals, read from the same lexer the parser uses rather than recognized again, in a file of the given kind: the tokens a document carries with no symbol table at all.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL