diff --git a/client/package.json b/client/package.json index ac08757..0a49af7 100644 --- a/client/package.json +++ b/client/package.json @@ -3,7 +3,7 @@ "description": "A language server for Verilog", "author": "chrehall68", "license": "MIT", - "version": "1.0.5", + "version": "1.0.6", "repository": { "type": "git", "url": "https://github.com/chrehall68/vls" diff --git a/server/internal/vlsp/semtokens.go b/server/internal/vlsp/semtokens.go index 31570c1..f23d3d5 100644 --- a/server/internal/vlsp/semtokens.go +++ b/server/internal/vlsp/semtokens.go @@ -31,11 +31,12 @@ func GetSemanticTokensOptions() SemanticTokensOptions { protocol.SemanticTokenType, // 0 protocol.SemanticTokenComment, // 1 protocol.SemanticTokenNumber, // 2 - protocol.SemanticTokenMacro, // 3 + protocol.SemanticTokenKeyword, // 3 protocol.SemanticTokenVariable, // 4 protocol.SemanticTokenClass, // 5 protocol.SemanticTokenParameter, // 6 protocol.SemanticTokenFunction, // 7 + protocol.SemanticTokenMacro, // 8 }, TokenModifiers: []protocol.SemanticTokenModifiers{}, }, @@ -44,7 +45,7 @@ func GetSemanticTokensOptions() SemanticTokensOptions { } } -func Encode(tokens []lang.Token) []uint32 { +func (h Handler) Encode(tokens []lang.Token) []uint32 { result := []uint32{} prevLine := 0 prevCharacter := 0 @@ -87,6 +88,14 @@ func Encode(tokens []lang.Token) []uint32 { "signed": 7, "dollar": 7, "pound": 7, + // 8 is reserved for defined identifiers + } + // flattened defines + flattenedDefines := map[string]bool{} + for _, defines := range h.state.defines { + for _, def := range defines { + flattenedDefines["`"+def.Identifier.Value] = true + } } addToken := func(token lang.Token) { @@ -98,6 +107,12 @@ func Encode(tokens []lang.Token) []uint32 { prevCharacter = 0 } + // special case for defined identifiers + _, ok := flattenedDefines[token.Value] + if token.Type == "identifier" && ok { + val = 8 + } + // add into result result = append(result, uint32(token.Line()-prevLine), uint32(token.StartCharacter()-prevCharacter), uint32(len(token.Value)), val, 0) @@ -177,7 +192,7 @@ func (h Handler) SemanticTokensFull(ctx context.Context, params *protocol.Semant // encode result := &protocol.SemanticTokens{ - Data: Encode(tokens), + Data: h.Encode(tokens), } h.state.log.Sugar().Info("SemanticTokensFull result: ", result)