Skip to content

Commit

Permalink
bump version, highlight defines as macros
Browse files Browse the repository at this point in the history
  • Loading branch information
chrehall68 committed Nov 22, 2024
1 parent 3bf8743 commit 7445a67
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 18 additions & 3 deletions server/internal/vlsp/semtokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
},
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 7445a67

Please sign in to comment.