Documentation
¶
Index ¶
- Constants
- Variables
- func FormatActionLabel(action ActionType, deco Decoration) string
- func FormatLineRef(startLine, endLine int) string
- func FormatReview(result *ReviewResult, d *Document, filePath string) string
- func FormatReviews(files []FileReview) string
- func SaveViewedState(path string, state *ViewedState) error
- func StatePath(filePath string) string
- type ActionType
- type Decoration
- type Document
- func (d *Document) AllSections() []*Section
- func (d *Document) DiffLineSections(info *diff.Info) []string
- func (d *Document) FindSection(id string) *Section
- func (d *Document) HasOverview() bool
- func (d *Document) LineSections() []string
- func (d *Document) Quote(info *diff.Info, start, end int, side string) []string
- func (d *Document) SearchSections(query string) map[string]bool
- type File
- type FileReview
- type ReviewComment
- type ReviewResult
- type Section
- type Status
- type ViewedState
Constants ¶
const DefaultAction = ActionQuestion
DefaultAction is the default action type for new comments.
const OverviewSectionID = "overview"
OverviewSectionID is the virtual section ID used for file-level comments on the overview/preamble.
const OverviewTitle = "Overview"
OverviewTitle is the name the overview is listed and searched by.
Variables ¶
var ActionLabels = []ActionType{ ActionSuggestion, ActionIssue, ActionQuestion, ActionNitpick, ActionTodo, ActionThought, ActionNote, ActionPraise, ActionChore, }
ActionLabels is the ordered list of action labels for Tab cycling.
var DecorationLabels = []Decoration{ DecorationNone, DecorationNonBlocking, DecorationBlocking, DecorationIfMinor, }
DecorationLabels is the ordered list of decoration labels for cycling.
Functions ¶
func FormatActionLabel ¶
func FormatActionLabel(action ActionType, deco Decoration) string
FormatActionLabel formats an action and decoration pair for display.
func FormatLineRef ¶ added in v0.6.0
FormatLineRef formats a line reference from start and end line numbers. Returns "L10" for single line, "L10-L15" for range, or "" if startLine is 0.
func FormatReview ¶
func FormatReview(result *ReviewResult, d *Document, filePath string) string
FormatReview formats a ReviewResult for a single file as a Markdown string. Section-level comments are grouped under section headings. Line-level comments are listed separately by line number.
func FormatReviews ¶ added in v0.10.0
func FormatReviews(files []FileReview) string
FormatReviews formats reviews for several files as one Markdown document. Each file gets its own "## path" heading with section headings nested one level deeper. Files without comments are omitted; returns "" if none have any.
func SaveViewedState ¶
func SaveViewedState(path string, state *ViewedState) error
SaveViewedState writes the viewed state to a JSON file.
Types ¶
type ActionType ¶
type ActionType string
ActionType is the type of review action, based on Conventional Comments labels.
const ( ActionSuggestion ActionType = "suggestion" ActionIssue ActionType = "issue" ActionQuestion ActionType = "question" ActionNitpick ActionType = "nitpick" ActionTodo ActionType = "todo" ActionThought ActionType = "thought" ActionNote ActionType = "note" ActionPraise ActionType = "praise" ActionChore ActionType = "chore" )
func ParseAction ¶ added in v0.12.0
func ParseAction(s string) (ActionType, bool)
ParseAction returns the ActionType for a label string.
type Decoration ¶
type Decoration string
Decoration is the decoration modifier for a Conventional Comment.
const ( DecorationNone Decoration = "" DecorationNonBlocking Decoration = "non-blocking" DecorationBlocking Decoration = "blocking" DecorationIfMinor Decoration = "if-minor" )
func ParseDecoration ¶ added in v0.12.0
func ParseDecoration(s string) (Decoration, bool)
ParseDecoration returns the Decoration for a label string; "" is DecorationNone.
type Document ¶
type Document struct {
Title string // Leading H1 heading text ("" when the document has none)
Preamble string // Text before the first heading
Sections []*Section // Top-level sections
SourceLines []string // Raw source lines (for line-level commenting)
}
Document is the parsed structure of an entire Markdown file.
func Parse ¶
Parse parses a Markdown source into a Document structure. It uses goldmark to build an AST and walks headings to create sections.
func (*Document) AllSections ¶
AllSections returns a flat list of all sections in depth-first order.
func (*Document) DiffLineSections ¶ added in v0.12.0
DiffLineSections returns the ID of the section each diff line belongs to. Added and context lines belong to the section of their new-file line. Removed lines no longer exist in the new file, so they follow the nearest preceding line that does (or the next one at the start of the diff). The lines of a section are therefore contiguous in the diff.
func (*Document) FindSection ¶
FindSection returns the section with the given ID, or nil if not found.
func (*Document) HasOverview ¶ added in v0.12.0
HasOverview reports whether the section list starts with the overview entry: only when there is a preamble to show.
func (*Document) LineSections ¶ added in v0.12.0
LineSections returns the ID of the section each source line belongs to (index i is line i+1): the last section whose heading starts at or before the line, or OverviewSectionID before the first heading.
func (*Document) Quote ¶ added in v0.12.0
Quote returns the source text a line comment on start..end (1-based, inclusive; end 0 means start only) quotes: the document's lines, or with info the diff lines on side (see diff.Line.Position).
func (*Document) SearchSections ¶ added in v0.12.0
SearchSections returns the IDs of the sections a search for query shows: those whose ID, title or body contain it (ignoring case), with their ancestors and descendants. The overview, when listed, matches by name only. An empty query matches nothing.
type File ¶ added in v0.12.0
type File struct {
Path string
Doc *Document
Diff *diff.Info // nil: review the full source instead of a diff
Viewed *ViewedState // nil: viewed marks live only for the session
}
File is a file to review, as the TUI and the browser receive it.
type FileReview ¶ added in v0.10.0
type FileReview struct {
Path string
Doc *Document
Review *ReviewResult
}
FileReview pairs a reviewed file with its parsed document and comments.
type ReviewComment ¶
type ReviewComment struct {
SectionID string // Target section ID
Action ActionType // Comment action type
Decoration Decoration // Comment decoration (e.g. non-blocking, blocking)
Body string // Comment body text
StartLine int // 1-based start line (0 = section-level comment)
EndLine int // 1-based end line (0 = single line if StartLine > 0)
Side string // "RIGHT" or "LEFT" (for diff comments)
Quote []string // source text of the commented lines (line-level only)
}
ReviewComment is a review comment on a single section.
func (*ReviewComment) FormatLabel ¶
func (c *ReviewComment) FormatLabel() string
FormatLabel returns the formatted label string for display. With decoration: "action (decoration)", without: "action".
func (*ReviewComment) FormatLineRef ¶ added in v0.6.0
func (c *ReviewComment) FormatLineRef() string
FormatLineRef returns a line reference string for display. Returns "L10" for single line, "L10-L15" for range, or "" for section-level.
func (*ReviewComment) IsRemoved ¶ added in v0.10.0
func (c *ReviewComment) IsRemoved() bool
IsRemoved reports whether the comment targets removed (old-side) diff lines.
type ReviewResult ¶
type ReviewResult struct {
Comments []ReviewComment
}
ReviewResult holds the entire review output.
func NewReviewResult ¶ added in v0.12.0
func NewReviewResult(doc *Document, comments []ReviewComment) *ReviewResult
NewReviewResult returns the comments in document order, which the output follows: the overview first, then the sections depth-first, keeping the given order within a section. Comments on unknown sections are dropped.
func (*ReviewResult) Status ¶ added in v0.12.0
func (r *ReviewResult) Status() Status
Status returns the status of a submitted review: approved when it has no comments.
type Section ¶
type Section struct {
ID string // Auto-numbered: "S1", "S1.1", "S2", etc.
Title string // Heading text (without the "## " prefix)
Level int // Heading level (2=##, 3=###, ...)
Body string // Markdown text from heading to next heading
Children []*Section // Sub-sections (lower-level headings)
Parent *Section // Parent section (nil for top-level)
StartLine int // 1-based line number of heading (0 = not set)
EndLine int // 1-based line number of last body line (0 = not set)
}
Section is a single section in a document, corresponding to one heading.
type ViewedState ¶
ViewedState tracks which sections have been viewed and their content hashes.
func LoadViewedState ¶
func LoadViewedState(path string) *ViewedState
LoadViewedState reads a viewed state file. Returns an empty state on any error.
func NewViewedState ¶
func NewViewedState() *ViewedState
NewViewedState creates an empty ViewedState.
func (*ViewedState) IsSectionViewed ¶
func (vs *ViewedState) IsSectionViewed(s *Section) bool
IsSectionViewed returns true if the section's title is tracked and its content hash matches.
func (*ViewedState) MarkViewed ¶
func (vs *ViewedState) MarkViewed(s *Section)
MarkViewed records a section as viewed with its current content hash.
func (*ViewedState) UnmarkViewed ¶
func (vs *ViewedState) UnmarkViewed(s *Section)
UnmarkViewed removes a section's viewed status.