1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 "golang.org/x/tools/internal/lsp/protocol"
13 "golang.org/x/tools/internal/span"
14 "golang.org/x/tools/internal/tool"
17 // foldingRanges implements the folding_ranges verb for gopls
18 type foldingRanges struct {
22 func (r *foldingRanges) Name() string { return "folding_ranges" }
23 func (r *foldingRanges) Usage() string { return "<file>" }
24 func (r *foldingRanges) ShortHelp() string { return "display selected file's folding ranges" }
25 func (r *foldingRanges) DetailedHelp(f *flag.FlagSet) {
26 fmt.Fprint(f.Output(), `
29 $ gopls folding_ranges helper/helper.go
34 func (r *foldingRanges) Run(ctx context.Context, args ...string) error {
36 return tool.CommandLineErrorf("folding_ranges expects 1 argument (file)")
39 conn, err := r.app.connect(ctx)
43 defer conn.terminate(ctx)
45 from := span.Parse(args[0])
46 file := conn.AddFile(ctx, from.URI())
51 p := protocol.FoldingRangeParams{
52 TextDocument: protocol.TextDocumentIdentifier{
53 URI: protocol.URIFromSpanURI(from.URI()),
57 ranges, err := conn.FoldingRange(ctx, &p)
62 for _, r := range ranges {
63 fmt.Printf("%v:%v-%v:%v\n",