Skip to content

Commit 81dbc8f

Browse files
committed
semantically tokenize export comments
1 parent e58dfd3 commit 81dbc8f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

gopls/internal/golang/semtok.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ func (tv *tokenVisitor) comment(c *ast.Comment, importByName map[string]*types.P
164164
if strings.HasPrefix(c.Text, "//go:") {
165165
tv.godirective(c)
166166
return
167+
} else if strings.HasPrefix(c.Text, "//export") {
168+
tv.goexport(c)
169+
return
167170
}
168171

169172
pkgScope := tv.pkg.Types().Scope()
@@ -923,6 +926,21 @@ func (tv *tokenVisitor) godirective(c *ast.Comment) {
923926
}
924927
}
925928

929+
func (tv *tokenVisitor) goexport(c *ast.Comment) {
930+
funcName := strings.TrimPrefix(c.Text, "//export ")
931+
932+
// Make the 'export func' part stand out, the rest is comments.
933+
tv.token(c.Pos(), len("//"), semtok.TokComment)
934+
935+
exportStart := c.Pos() + token.Pos(len("//"))
936+
tv.token(exportStart, len("export "), semtok.TokNamespace)
937+
938+
if len(funcName) > 0 {
939+
funcStart := c.Pos() + token.Pos(len("//export "))
940+
tv.token(funcStart, len(funcName), semtok.TokFunction)
941+
}
942+
}
943+
926944
// Go 1.20 strings.CutPrefix.
927945
func stringsCutPrefix(s, prefix string) (after string, found bool) {
928946
if !strings.HasPrefix(s, prefix) {

0 commit comments

Comments
 (0)