1 // Copyright 2020 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.
10 "golang.org/x/tools/internal/event"
11 "golang.org/x/tools/internal/lsp/protocol"
12 "golang.org/x/tools/internal/lsp/source"
15 func Format(ctx context.Context, snapshot source.Snapshot, fh source.FileHandle) ([]protocol.TextEdit, error) {
16 ctx, done := event.Start(ctx, "mod.Format")
19 pm, err := snapshot.ParseMod(ctx, fh)
23 formatted, err := pm.File.Format()
27 // Calculate the edits to be made due to the change.
28 diff, err := snapshot.View().Options().ComputeEdits(fh.URI(), string(pm.Mapper.Content), string(formatted))
32 return source.ToProtocolEdits(pm.Mapper, diff)