Skip to content

Commit

Permalink
Fixes for overlapping tokens in some scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
kralicky committed Dec 29, 2023
1 parent 8227521 commit 94012e2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/lsp/semantic.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ func computeSemanticTokens(cache *Cache, e *semanticItems, walkOptions ...ast.Wa
}

func (s *semanticItems) mktokens(node ast.Node, path []ast.Node, tt tokenType, mods tokenModifier) {
if node == (ast.NoSourceNode{}) {
return
}

info := s.parseRes.AST().NodeInfo(node)
if !info.IsValid() {
return
Expand Down Expand Up @@ -399,6 +403,7 @@ func (s *semanticItems) inspect(cache *Cache, node ast.Node, walkOptions ...ast.
}
walkOptions = append(walkOptions, tracker.AsWalkOptions()...)
embeddedStringLiterals := make(map[*ast.StringLiteralNode]struct{})

// NB: when calling mktokens in composite node visitors:
// - ensure node paths are manually adjusted if creating tokens for a child node
// - ensure tokens for child nodes are created in the correct order
Expand Down Expand Up @@ -453,7 +458,11 @@ func (s *semanticItems) inspect(cache *Cache, node ast.Node, walkOptions ...ast.
if id := string(node.FldType.AsIdentifier()); protocompile.IsScalarType(id) || protocompile.IsWellKnownType(protoreflect.FullName(id)) {
modifier = semanticModifierDefaultLibrary
}
s.mktokens(node.FldType, append(tracker.Path(), node.FldType), semanticTypeType, modifier)
if !node.Label.IsPresent() || node.Label.Start() != node.FldType.Start() {
// for incomplete nodes, the field type might be the same as the label
// if the type is missing
s.mktokens(node.FldType, append(tracker.Path(), node.FldType), semanticTypeType, modifier)
}
s.mktokens(node.FieldName(), append(tracker.Path(), node.FieldName()), semanticTypeVariable, semanticModifierDefinition)
return nil
},
Expand Down Expand Up @@ -560,10 +569,6 @@ func (s *semanticItems) inspect(cache *Cache, node ast.Node, walkOptions ...ast.
s.mktokens(node.Name, append(tracker.Path(), node.Name), semanticTypeEnumMember, 0)
return nil
},
DoVisitTerminalNode: func(node ast.TerminalNode) error {
s.mkcomments(node)
return nil
},
}, walkOptions...)
}

Expand Down

0 comments on commit 94012e2

Please sign in to comment.