Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions gopls/internal/golang/semtok.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ func (tv *tokenVisitor) comment(c *ast.Comment, importByName map[string]*types.P
if strings.HasPrefix(c.Text, "//go:") {
tv.godirective(c)
return
} else if strings.HasPrefix(c.Text, "//export") {
tv.goexport(c)
return
}

pkgScope := tv.pkg.Types().Scope()
Expand Down Expand Up @@ -923,6 +926,21 @@ func (tv *tokenVisitor) godirective(c *ast.Comment) {
}
}

func (tv *tokenVisitor) goexport(c *ast.Comment) {
funcName := strings.TrimPrefix(c.Text, "//export ")

// Make the 'export func' part stand out, the rest is comments.
tv.token(c.Pos(), len("//"), semtok.TokComment)

exportStart := c.Pos() + token.Pos(len("//"))
tv.token(exportStart, len("export "), semtok.TokNamespace)

if len(funcName) > 0 {
funcStart := c.Pos() + token.Pos(len("//export "))
tv.token(funcStart, len(funcName), semtok.TokFunction)
}
}

// Go 1.20 strings.CutPrefix.
func stringsCutPrefix(s, prefix string) (after string, found bool) {
if !strings.HasPrefix(s, prefix) {
Expand Down