6 "golang.org/x/tools/internal/event"
7 "golang.org/x/tools/internal/lsp/protocol"
8 "golang.org/x/tools/internal/lsp/source"
11 func Format(ctx context.Context, snapshot source.Snapshot, fh source.FileHandle) ([]protocol.TextEdit, error) {
12 ctx, done := event.Start(ctx, "mod.Format")
15 pm, err := snapshot.ParseMod(ctx, fh)
19 formatted, err := pm.File.Format()
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)