semtok

package
v0.17.0-pre.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

The semtok package provides an encoder for LSP's semantic tokens.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(
	tokens []Token,
	noStrings, noNumbers bool,
	types, modifiers []string) []uint32

Encode returns the LSP encoding of a sequence of tokens. The noStrings, noNumbers options cause strings, numbers to be skipped. The lists of types and modifiers determines the bitfield encoding.

Types

type Modifier added in v0.17.0

type Modifier string
const (
	// LSP 3.18 standard modifiers
	// As with TokenTypes, clients get only the modifiers they request.
	//
	// If you add or uncomment a modifier, document it in
	// gopls/doc/features/passive.md#semantic-tokens.
	ModDefaultLibrary Modifier = "defaultLibrary" // for predeclared symbols
	ModDefinition     Modifier = "definition"     // for the declaring identifier of a symbol
	ModReadonly       Modifier = "readonly"       // for constants (TokVariable)

	// non-standard modifiers
	//
	// Since the type of a symbol is orthogonal to its kind,
	// (e.g. a variable can have function type),
	// we use modifiers for the top-level type constructor.
	ModArray     Modifier = "array"
	ModBool      Modifier = "bool"
	ModChan      Modifier = "chan"
	ModInterface Modifier = "interface"
	ModMap       Modifier = "map"
	ModNumber    Modifier = "number"
	ModPointer   Modifier = "pointer"
	ModSignature Modifier = "signature" // for function types
	ModSlice     Modifier = "slice"
	ModString    Modifier = "string"
	ModStruct    Modifier = "struct"
)

type Token

type Token struct {
	Line, Start uint32
	Len         uint32
	Type        TokenType
	Modifiers   []Modifier
}

A Token provides the extent and semantics of a token.

type TokenType

type TokenType string
const (
	// These are the tokens defined by LSP 3.18, but a client is
	// free to send its own set; any tokens that the server emits
	// that are not in this set are simply not encoded in the bitfield.
	//
	// If you add or uncomment a token type, document it in
	// gopls/doc/features/passive.md#semantic-tokens.
	TokComment   TokenType = "comment"       // for a comment
	TokFunction  TokenType = "function"      // for a function
	TokKeyword   TokenType = "keyword"       // for a keyword
	TokLabel     TokenType = "label"         // for a control label (LSP 3.18)
	TokMacro     TokenType = "macro"         // for text/template tokens
	TokMethod    TokenType = "method"        // for a method
	TokNamespace TokenType = "namespace"     // for an imported package name
	TokNumber    TokenType = "number"        // for a numeric literal
	TokOperator  TokenType = "operator"      // for an operator
	TokParameter TokenType = "parameter"     // for a parameter variable
	TokString    TokenType = "string"        // for a string literal
	TokType      TokenType = "type"          // for a type name (plus other uses)
	TokTypeParam TokenType = "typeParameter" // for a type parameter
	TokVariable  TokenType = "variable"      // for a var or const

)

Jump to

Keyboard shortcuts

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