const semDebug … func SemanticTokens(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, rng *protocol.Range) (*protocol.SemanticTokens, error) { … } type tokenVisitor … func (tv *tokenVisitor) visit() { … } var docLinkRegex … // comment emits semantic tokens for a comment. // If the comment contains doc links or "go:" directives, // it emits a separate token for each link or directive and // each comment portion between them. func (tv *tokenVisitor) comment(c *ast.Comment, importByName map[string]*types.PkgName) { … } // token emits a token of the specified extent and semantics. func (tv *tokenVisitor) token(start token.Pos, length int, typ semtok.TokenType, modifiers ...semtok.Modifier) { … } // strStack converts the stack to a string, for debugging and error messages. func (tv *tokenVisitor) strStack() string { … } // srcLine returns the source text for n (truncated at first newline). func (tv *tokenVisitor) srcLine(n ast.Node) string { … } func (tv *tokenVisitor) inspect(n ast.Node) (descend bool) { … } func (tv *tokenVisitor) appendObjectModifiers(mods []semtok.Modifier, obj types.Object) (semtok.TokenType, []semtok.Modifier) { … } // appendTypeModifiers appends optional modifiers that describe the top-level // type constructor of t: "pointer", "map", etc. func appendTypeModifiers(mods []semtok.Modifier, t types.Type) []semtok.Modifier { … } func (tv *tokenVisitor) ident(id *ast.Ident) { … } // isParam reports whether the position is that of a parameter name of // an enclosing function. func (tv *tokenVisitor) isParam(pos token.Pos) bool { … } // unkIdent handles identifiers with no types.Object (neither use nor // def), use the parse stack. // A lot of these only happen when the package doesn't compile, // but in that case it is all best-effort from the parse tree. func (tv *tokenVisitor) unkIdent(id *ast.Ident) (semtok.TokenType, []semtok.Modifier) { … } // multiline emits a multiline token (`string` or /*comment*/). func (tv *tokenVisitor) multiline(start, end token.Pos, tok semtok.TokenType) { … } // findKeyword returns the position of a keyword by searching within // the specified range, for when it cannot be exactly known from the AST. // It returns NoPos if the keyword was not present in the source due to parse error. func (tv *tokenVisitor) findKeyword(keyword string, start, end token.Pos) token.Pos { … } func (tv *tokenVisitor) importSpec(spec *ast.ImportSpec) { … } // errorf logs an error and reports a bug. func (tv *tokenVisitor) errorf(format string, args ...any) { … } var godirectives … // Tokenize godirective at the start of the comment c, if any, and the surrounding comment. // If there is any failure, emits the entire comment as a TokComment token. // Directives are highlighted as-is, even if used incorrectly. Typically there are // dedicated analyzers that will warn about misuse. func (tv *tokenVisitor) godirective(c *ast.Comment) { … } // Go 1.20 strings.CutPrefix. func stringsCutPrefix(s, prefix string) (after string, found bool) { … } func is[T any](x any) bool { … }