Skip to content

Commit 59bfed9

Browse files
committed
added semantic highlighting for custom types
1 parent 8bcbf99 commit 59bfed9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

handlers/semanticHighlighting.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func (t *semanticTokenizer) add(tok highlightedToken) {
128128
}
129129

130130
func (t *semanticTokenizer) VisitVarDecl(d *ast.VarDecl) ast.VisitResult {
131+
t.add(newHightlightedToken(d.TypeRange, t.doc, protocol.SemanticTokenTypeType, nil))
131132
t.add(newHightlightedToken(token.NewRange(&d.NameTok, &d.NameTok), t.doc, protocol.SemanticTokenTypeVariable, nil))
132133
return ast.VisitRecurse
133134
}
@@ -138,6 +139,11 @@ func (t *semanticTokenizer) VisitFuncDecl(d *ast.FuncDecl) ast.VisitResult {
138139
name := &d.Parameters[i].Name
139140
t.add(newHightlightedToken(token.NewRange(name, name), t.doc, protocol.SemanticTokenTypeParameter, nil))
140141
}
142+
for i := range d.Parameters {
143+
typeRange := d.Parameters[i].TypeRange
144+
t.add(newHightlightedToken(typeRange, t.doc, protocol.SemanticTokenTypeType, nil))
145+
}
146+
t.add(newHightlightedToken(d.ReturnTypeRange, t.doc, protocol.SemanticTokenTypeType, nil))
141147
return ast.VisitRecurse
142148
}
143149

@@ -152,6 +158,18 @@ func (t *semanticTokenizer) VisitStructDecl(d *ast.StructDecl) ast.VisitResult {
152158
return ast.VisitSkipChildren
153159
}
154160

161+
func (t *semanticTokenizer) VisitTypeAliasDecl(d *ast.TypeAliasDecl) ast.VisitResult {
162+
t.add(newHightlightedToken(d.UnderlyingRange, t.doc, protocol.SemanticTokenTypeClass, nil))
163+
t.add(newHightlightedToken(d.NameTok.Range, t.doc, protocol.SemanticTokenTypeClass, nil))
164+
return ast.VisitRecurse
165+
}
166+
167+
func (t *semanticTokenizer) VisitTypeDefDecl(d *ast.TypeDefDecl) ast.VisitResult {
168+
t.add(newHightlightedToken(d.NameTok.Range, t.doc, protocol.SemanticTokenTypeClass, nil))
169+
t.add(newHightlightedToken(d.UnderlyingRange, t.doc, protocol.SemanticTokenTypeClass, nil))
170+
return ast.VisitRecurse
171+
}
172+
155173
func (t *semanticTokenizer) VisitIdent(e *ast.Ident) ast.VisitResult {
156174
t.add(newHightlightedToken(e.GetRange(), t.doc, protocol.SemanticTokenTypeVariable, nil))
157175
return ast.VisitRecurse

0 commit comments

Comments
 (0)