Skip to content

Commit

Permalink
Clamp docComments indexing when cleaning up old docs
Browse files Browse the repository at this point in the history
Fixes #70
  • Loading branch information
gagbo committed Oct 13, 2023
1 parent 7c14d18 commit 6fb3c8d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/generate/documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package generate // import "github.com/autometrics-dev/autometrics-go/internal/g

import (
"fmt"
"math"
"strings"

internal "github.com/autometrics-dev/autometrics-go/internal/autometrics"
Expand Down Expand Up @@ -40,7 +41,9 @@ func cleanUpAutometricsComments(ctx internal.GeneratorContext, funcDeclaration *

if oldStartCommentIndex >= 0 && oldEndCommentIndex > oldStartCommentIndex {
// We also remove the header and the footer that are used as block separation
docComments = append(docComments[:oldStartCommentIndex-1], docComments[oldEndCommentIndex+2:]...)
amCommentSectionStart := int(math.Max(0, float64(oldStartCommentIndex-1)))
amCommentSectionEnd := int(math.Min(float64(len(docComments)), float64(oldEndCommentIndex+2)))
docComments = append(docComments[:amCommentSectionStart], docComments[amCommentSectionEnd:]...)

// Remove the generated links from former passes
if ctx.DocumentationGenerator != nil {
Expand Down

0 comments on commit 6fb3c8d

Please sign in to comment.