1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:04:45 -07:00
go/internal/lsp/folding_range.go

29 lines
678 B
Go
Raw Normal View History

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.session.Options().LineFoldingOnly)
if err != nil {
return nil, err
}
return source.ToProtocolFoldingRanges(m, ranges)
}