mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
Support textDocument/foldingRange request. Provide folding ranges for multiline comment blocks, declarations, block statements, field lists, case clauses, and call expressions. Fixes golang/go#32987 Change-Id: I9c76e850ffa0e5bb65bee273d8ee40577c342f92 Reviewed-on: https://go-review.googlesource.com/c/tools/+/192257 Run-TryBot: Suzy Mueller <suzmue@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
29 lines
641 B
Go
29 lines
641 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)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return source.ToProtocolFoldingRanges(m, ranges)
|
|
}
|