MCPcopy Create free account
hub / github.com/openclaw/gogcli / targetRanges

Method targetRanges

internal/cmd/docs_format.go:221–263  ·  view source on GitHub ↗
(ctx context.Context, svc *docs.Service, docID string)

Source from the content-addressed store, hash-verified

219}
220
221func (c *DocsFormatCmd) targetRanges(ctx context.Context, svc *docs.Service, docID string) ([]docsFormatTargetRange, docsRequestTarget, error) {
222 loaded, err := loadDocsTargetSegment(ctx, svc, docID, c.Tab, c.Segment)
223 if err != nil {
224 return nil, docsRequestTarget{}, err
225 }
226 targetDoc := loaded.target
227 target := docsRequestTarget{TabID: loaded.tabID, SegmentID: loaded.segmentID, SegmentKind: loaded.segmentKind}
228
229 var ranges []docsedit.TextRange
230 if strings.TrimSpace(c.Match) == "" {
231 start := int64(1)
232 if target.SegmentID != "" {
233 start = 0
234 }
235 end := docsDocumentEndIndex(targetDoc) - 1
236 if end > start {
237 ranges = []docsedit.TextRange{{StartIndex: start, EndIndex: end}}
238 }
239 } else {
240 ranges = docsedit.FindTextRanges(targetDoc, c.Match, docsedit.SearchOptions{
241 MatchCase: c.MatchCase,
242 PreserveHTMLEntities: true,
243 RequireTextSegment: true,
244 })
245 if !c.MatchAll && len(ranges) > 1 {
246 ranges = ranges[:1]
247 }
248 }
249
250 paragraphs := []docssed.DocumentParagraph(nil)
251 if projection := docssed.ProjectDocument(targetDoc); projection.Legacy != nil {
252 paragraphs = projection.Legacy.Paragraphs
253 }
254 targets := make([]docsFormatTargetRange, 0, len(ranges))
255 for _, r := range ranges {
256 target := docsFormatTargetRange{TextRange: r}
257 if c.Format.createsBullets() {
258 target.BulletParagraphs = docsFormatBulletParagraphs(paragraphs, r.StartIndex, r.EndIndex)
259 }
260 targets = append(targets, target)
261 }
262 return targets, target, nil
263}
264
265type docsFormatTargetRange struct {
266 docsedit.TextRange

Callers 1

RunMethod · 0.95

Calls 6

FindTextRangesFunction · 0.92
ProjectDocumentFunction · 0.92
loadDocsTargetSegmentFunction · 0.85
docsDocumentEndIndexFunction · 0.85
createsBulletsMethod · 0.80

Tested by

no test coverage detected