(ctx context.Context, sourceFile *ast.SourceFile)
| 99 | } |
| 100 | |
| 101 | func (l *LanguageService) addRegionOutliningSpans(ctx context.Context, sourceFile *ast.SourceFile) []*lsproto.FoldingRange { |
| 102 | regions := make([]*lsproto.FoldingRange, 0, 40) |
| 103 | out := make([]*lsproto.FoldingRange, 0, 40) |
| 104 | lineStarts := scanner.GetECMALineStarts(sourceFile) |
| 105 | for _, currentLineStart := range lineStarts { |
| 106 | lineEnd := getLineEndOfPosition(sourceFile, int(currentLineStart)) |
| 107 | lineText := sourceFile.Text()[currentLineStart:lineEnd] |
| 108 | result := parseRegionDelimiter(lineText) |
| 109 | if result == nil || isInComment(sourceFile, int(currentLineStart), astnav.GetTokenAtPosition(sourceFile, int(currentLineStart))) != nil { |
| 110 | continue |
| 111 | } |
| 112 | |
| 113 | if result.isStart { |
| 114 | commentStart := l.createLspPosition(strings.Index(sourceFile.Text()[currentLineStart:lineEnd], "//")+int(currentLineStart), sourceFile) |
| 115 | foldingRangeKindRegion := lsproto.FoldingRangeKindRegion |
| 116 | region := &lsproto.FoldingRange{ |
| 117 | StartLine: commentStart.Line, |
| 118 | StartCharacter: &commentStart.Character, |
| 119 | Kind: &foldingRangeKindRegion, |
| 120 | } |
| 121 | if supportsCollapsedText(ctx) { |
| 122 | collapsedText := "#region" |
| 123 | if result.name != "" { |
| 124 | collapsedText = result.name |
| 125 | } |
| 126 | region.CollapsedText = &collapsedText |
| 127 | } |
| 128 | // Our spans start out with some initial data. |
| 129 | // On every `#endregion`, we'll come back to these `FoldingRange`s |
| 130 | // and fill in their EndLine/EndCharacter. |
| 131 | regions = append(regions, region) |
| 132 | } else { |
| 133 | if len(regions) > 0 { |
| 134 | region := regions[len(regions)-1] |
| 135 | regions = regions[:len(regions)-1] |
| 136 | endingPosition := l.createLspPosition(lineEnd, sourceFile) |
| 137 | region.EndLine = endingPosition.Line |
| 138 | region.EndCharacter = &endingPosition.Character |
| 139 | out = append(out, region) |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | return out |
| 144 | } |
| 145 | |
| 146 | func visitNode(ctx context.Context, n *ast.Node, depthRemaining int, sourceFile *ast.SourceFile, l *LanguageService) []*lsproto.FoldingRange { |
| 147 | if n.Flags&ast.NodeFlagsReparsed != 0 || depthRemaining == 0 || ctx.Err() != nil { |
no test coverage detected