Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201028153306-37f0764111ff / internal / lsp / mod / format.go
1 package mod
2
3 import (
4         "context"
5
6         "golang.org/x/tools/internal/event"
7         "golang.org/x/tools/internal/lsp/protocol"
8         "golang.org/x/tools/internal/lsp/source"
9 )
10
11 func Format(ctx context.Context, snapshot source.Snapshot, fh source.FileHandle) ([]protocol.TextEdit, error) {
12         ctx, done := event.Start(ctx, "mod.Format")
13         defer done()
14
15         pm, err := snapshot.ParseMod(ctx, fh)
16         if err != nil {
17                 return nil, err
18         }
19         formatted, err := pm.File.Format()
20         if err != nil {
21                 return nil, err
22         }
23         // Calculate the edits to be made due to the change.
24         diff := snapshot.View().Options().ComputeEdits(fh.URI(), string(pm.Mapper.Content), string(formatted))
25         return source.ToProtocolEdits(pm.Mapper, diff)
26 }