1 files changed,
2 insertions(+),
13 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-09-02 20:12:41 +0300
Authored at:
2026-09-02 20:02:13 +0300
Change ID:
mrzxmvtmwxlzuuwzymmlnruzqrkopqxw
Parent:
ed6cfe6
M
internal/lsp/textdocument_folding_range.go
··· 27 27 return ranges, nil 28 28 } 29 29 30 -// foldingRangesFor folds every foldable structure in a journal's top-level entries: 31 -// posting blocks, directive sub-blocks, comment runs, comment blocks, and apply/end pairs. 32 30 func foldingRangesFor(entries []ast.Entry) []protocol.FoldingRange { 33 31 ranges := make([]protocol.FoldingRange, 0, len(entries)) // each entry folds to at most one range 34 32 var ( ··· 73 71 return ranges 74 72 } 75 73 76 -// appendFold appends r, skipping nil. 77 74 func appendFold(ranges []protocol.FoldingRange, r *protocol.FoldingRange) []protocol.FoldingRange { 78 75 if r != nil { 79 76 ranges = append(ranges, *r) ··· 81 78 return ranges 82 79 } 83 80 84 -// postingsFold folds the posting block of a transaction, leaving the header visible. 85 81 func postingsFold(postings []ast.Posting) *protocol.FoldingRange { 86 82 if len(postings) < 2 { 87 83 return nil ··· 94 90 ) 95 91 } 96 92 97 -// accountDirectiveFold folds the indented subdirective block after an "account" line. 98 93 func accountDirectiveFold(ad *ast.AccountDirective) *protocol.FoldingRange { 99 94 if len(ad.Subdirectives) < 2 { 100 95 return nil ··· 107 102 ) 108 103 } 109 104 110 -// commentBlockDirectiveFold folds a "comment" ... "end comment" block, leaving the header visible. 111 -// The directive span extends past the block, so the end line is derived from the content. 112 105 func commentBlockDirectiveFold(cb *ast.CommentBlockDirective) *protocol.FoldingRange { 113 106 start := uint32(cb.Span.Start.Line - 1) 114 107 end := start + uint32(strings.Count(cb.Content, "\n")) + 1 // +1 for the "end comment" line 115 108 return foldRange(start, end, protocol.FoldingRangeKindComment) 116 109 } 117 110 118 -// commentRunFold folds consecutive comment lines into a single range. 119 111 func commentRunFold(comments []*ast.Comment) *protocol.FoldingRange { 120 112 if len(comments) < 2 { 121 113 return nil ··· 127 119 ) 128 120 } 129 121 130 -// applyKeyword returns the first word of an apply/end directive expr ("apply tag work" → "tag"). 131 122 func applyKeyword(expr string) string { 132 - if i := strings.IndexByte(expr, ' '); i >= 0 { 133 - return expr[:i] 123 + if before, _, ok := strings.Cut(expr, " "); ok { 124 + return before 134 125 } 135 126 return expr 136 127 } 137 128 138 -// applyFold folds an "apply" ... "end" block. 139 129 func applyFold(a *ast.ApplyDirective, end *ast.EndDirective) *protocol.FoldingRange { 140 130 return foldRange( 141 131 uint32(a.Span.Start.Line-1), ··· 144 134 ) 145 135 } 146 136 147 -// foldRange returns nil when the range is not foldable (single line). 148 137 func foldRange(startLine, endLine uint32, kind protocol.FoldingRangeKind) *protocol.FoldingRange { 149 138 if endLine <= startLine { 150 139 return nil