mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
If the client registers with foldingRange.lineFoldingOnly = true, only return folding ranges that span multiple lines. Do this as they are computed, so that if other filtering is applied later, we do not include ranges that would go unused by the client anyway. Change-Id: I27ea24428d25f180e26892de0f6d16c211225bf7 Reviewed-on: https://go-review.googlesource.com/c/tools/+/192477 Run-TryBot: Suzy Mueller <suzmue@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
29 lines
660 B
Go
29 lines
660 B
Go
package lsp
|
|
|
|
import (
|
|
"context"
|
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
"golang.org/x/tools/internal/lsp/source"
|
|
"golang.org/x/tools/internal/span"
|
|
)
|
|
|
|
func (s *Server) foldingRange(ctx context.Context, params *protocol.FoldingRangeParams) ([]protocol.FoldingRange, error) {
|
|
uri := span.NewURI(params.TextDocument.URI)
|
|
view := s.session.ViewOf(uri)
|
|
f, err := getGoFile(ctx, view, uri)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
m, err := getMapper(ctx, f)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ranges, err := source.FoldingRange(ctx, view, f, s.lineFoldingOnly)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return source.ToProtocolFoldingRanges(m, ranges)
|
|
}
|