From 92d91822c8887121b82b2cd2f48a0bb00d4a99d4 Mon Sep 17 00:00:00 2001 From: Anders Eknert Date: Thu, 8 Aug 2024 11:08:05 +0200 Subject: [PATCH] Fix code lens issue with ref head rules Signed-off-by: Anders Eknert --- internal/lsp/server.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/internal/lsp/server.go b/internal/lsp/server.go index 58c22037..f6d22fb6 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -451,8 +451,6 @@ func (l *LanguageServer) StartCommandWorker(ctx context.Context) { params, ) case "regal.eval": - fmt.Fprintf(os.Stderr, "regal.eval called with params: %v\n", params) - if len(params.Arguments) != 3 { l.logError(fmt.Errorf("expected three arguments, got %d", len(params.Arguments))) @@ -1068,7 +1066,7 @@ func (l *LanguageServer) handleTextDocumentCodeLens( Command: "regal.eval", Arguments: &[]any{ module.Package.Location.File, - module.Package.Path.String() + "." + string(rule.Head.Name), + module.Package.Path.String() + "." + getRuleName(rule), rule.Head.Location.Row, }, }, @@ -1080,6 +1078,20 @@ func (l *LanguageServer) handleTextDocumentCodeLens( return codeLenses, nil } +func getRuleName(rule *ast.Rule) string { + parts := make([]string, 0, len(rule.Head.Ref())) + + for i, part := range rule.Head.Ref() { + if !part.Value.IsGround() && i > 0 { + break + } + + parts = append(parts, part.Value.String()) + } + + return strings.Join(parts, ".") +} + func (l *LanguageServer) handleTextDocumentCompletion( _ context.Context, _ *jsonrpc2.Conn,