Skip to content

Commit

Permalink
lsp: Generate correct rule name when during Eval
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Egan <[email protected]>
  • Loading branch information
charlieegan3 committed Aug 8, 2024
1 parent ff67859 commit e8943fc
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,16 @@ func (l *LanguageServer) StartCommandWorker(ctx context.Context) {
if err != nil {
fmt.Fprintf(os.Stderr, "failed to evaluate workspace path: %v\n", err)

err := l.conn.Notify(ctx, "window/showMessage", types.ShowMessageParams{
Type: 1, // error
Message: err.Error(),
})
if err != nil {
l.logError(fmt.Errorf("failed to notify client of eval error: %w", err))

break
}

break
}

Expand Down Expand Up @@ -1079,17 +1089,16 @@ func (l *LanguageServer) handleTextDocumentCodeLens(
}

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
}
result := rule.Head.Ref().String()

parts = append(parts, part.Value.String())
// only evaluate the top level rule name if there are refs
// e.g. my[foo].bar -> my
// bar.bar.bar -> bar.bar.bar
if i := strings.Index(result, "["); i > 0 {
return result[:i]
}

return strings.Join(parts, ".")
return result
}

func (l *LanguageServer) handleTextDocumentCompletion(
Expand Down

0 comments on commit e8943fc

Please sign in to comment.