Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools / gopls@v0.5.2 / internal / hooks / diff.go
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.
4
5 package hooks
6
7 import (
8         "github.com/sergi/go-diff/diffmatchpatch"
9         "golang.org/x/tools/internal/lsp/diff"
10         "golang.org/x/tools/internal/span"
11 )
12
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))
16         offset := 0
17         for _, d := range diffs {
18                 start := span.NewPoint(0, 0, offset)
19                 switch d.Type {
20                 case diffmatchpatch.DiffDelete:
21                         offset += len(d.Text)
22                         edits = append(edits, diff.TextEdit{Span: span.New(uri, start, span.NewPoint(0, 0, offset))})
23                 case diffmatchpatch.DiffEqual:
24                         offset += len(d.Text)
25                 case diffmatchpatch.DiffInsert:
26                         edits = append(edits, diff.TextEdit{Span: span.New(uri, start, span.Point{}), NewText: d.Text})
27                 }
28         }
29         return edits
30 }