Skip to content

Commit

Permalink
internal/hcl: fix insertion interpretation in diff
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Apr 14, 2022
1 parent fc41c2f commit bf12034
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/hcl/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ func diffLines(filename string, beforeLines, afterLines source.Lines) document.C

for _, group := range m.GetGroupedOpCodes(context) {
for _, c := range group {
beforeStart, beforeEnd := c.I1, c.I2
afterStart, afterEnd := c.J1, c.J2

if c.Tag == OpEqual {
continue
}

// lines to pick from the original document (to delete/replace/insert to)
beforeStart, beforeEnd := c.I1, c.I2
// lines to pick from the new document (to replace/insert ^ with)
afterStart, afterEnd := c.J1, c.J2

if c.Tag == OpReplace {
var rng *hcl.Range
var newBytes []byte
Expand Down Expand Up @@ -121,6 +123,10 @@ func diffLines(filename string, beforeLines, afterLines source.Lines) document.C
if beforeStart == beforeEnd {
line := beforeLines[beforeStart]
insertRng = line.Range.Ptr()

// We're inserting to the beginning of the line
// which we represent as 0-length range in HCL
insertRng.End = insertRng.Start
} else {
for i, line := range beforeLines[beforeStart:beforeEnd] {
if i == 0 {
Expand Down

0 comments on commit bf12034

Please sign in to comment.