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.
8 "github.com/sergi/go-diff/diffmatchpatch"
9 "golang.org/x/tools/internal/lsp/diff"
10 "golang.org/x/tools/internal/span"
13 func ComputeEdits(uri span.URI, before, after string) []diff.TextEdit {
14 diffs := diffmatchpatch.New().DiffMain(before, after, true)
15 edits := make([]diff.TextEdit, 0, len(diffs))
17 for _, d := range diffs {
18 start := span.NewPoint(0, 0, offset)
20 case diffmatchpatch.DiffDelete:
22 edits = append(edits, diff.TextEdit{Span: span.New(uri, start, span.NewPoint(0, 0, offset))})
23 case diffmatchpatch.DiffEqual:
25 case diffmatchpatch.DiffInsert:
26 edits = append(edits, diff.TextEdit{Span: span.New(uri, start, span.Point{}), NewText: d.Text})