Skip to content

Commit ff67859

Browse files
authoredAug 8, 2024··
Fix code lens issue with ref head rules (#973)
Signed-off-by: Anders Eknert <anders@styra.com>
1 parent 63e7155 commit ff67859

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed
 

‎internal/lsp/server.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,6 @@ func (l *LanguageServer) StartCommandWorker(ctx context.Context) {
451451
params,
452452
)
453453
case "regal.eval":
454-
fmt.Fprintf(os.Stderr, "regal.eval called with params: %v\n", params)
455-
456454
if len(params.Arguments) != 3 {
457455
l.logError(fmt.Errorf("expected three arguments, got %d", len(params.Arguments)))
458456

@@ -1068,7 +1066,7 @@ func (l *LanguageServer) handleTextDocumentCodeLens(
10681066
Command: "regal.eval",
10691067
Arguments: &[]any{
10701068
module.Package.Location.File,
1071-
module.Package.Path.String() + "." + string(rule.Head.Name),
1069+
module.Package.Path.String() + "." + getRuleName(rule),
10721070
rule.Head.Location.Row,
10731071
},
10741072
},
@@ -1080,6 +1078,20 @@ func (l *LanguageServer) handleTextDocumentCodeLens(
10801078
return codeLenses, nil
10811079
}
10821080

1081+
func getRuleName(rule *ast.Rule) string {
1082+
parts := make([]string, 0, len(rule.Head.Ref()))
1083+
1084+
for i, part := range rule.Head.Ref() {
1085+
if !part.Value.IsGround() && i > 0 {
1086+
break
1087+
}
1088+
1089+
parts = append(parts, part.Value.String())
1090+
}
1091+
1092+
return strings.Join(parts, ".")
1093+
}
1094+
10831095
func (l *LanguageServer) handleTextDocumentCompletion(
10841096
_ context.Context,
10851097
_ *jsonrpc2.Conn,

0 commit comments

Comments
 (0)
Please sign in to comment.