2019-08-28 19:48:29 -06:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-09-05 22:17:36 -06:00
|
|
|
ranges, err := source.FoldingRange(ctx, view, f, s.session.Options().LineFoldingOnly)
|
2019-08-28 19:48:29 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return source.ToProtocolFoldingRanges(m, ranges)
|
|
|
|
}
|