-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli: Fix diff for nested set unchanged elements #29983
Conversation
Unchanged elements in nested attributes backed by sets were previously misrendered as empty objects. This commit removes the additional brackets and adds a count of unchanged elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks for digging into this.
Looking at your "after" screenshot it still felt a little "off", though it did take me staring at it for quite a few minutes before I realized what was throwing me:
It seems like all of the lines after the opening - {
are missing one level of indentation, so the nested -
s are directly below the brace rather than indented relative to it.
While I guess it's a matter of opinion whether it's a "good thing", in all other cases we have created the effect of each additional nesting level adding four columns of indent and then having the change symbols ~
-
+
live inside the left "gutter" when they are present, as if they are annotations in the margin rather than part of the actual content. Notice for example how the closing ]
for ~ values = [
lines up with values
rather than with ~
.
It'd be totally reasonable to treat that as out of scope for what you were aiming to solve here, so I'm not intending this as a blocker for merging, but if it's something you can see an easy path to fix while you're there it'd be nice to make this consistent with the formatting elsewhere.
internal/command/format/diff_test.go
Outdated
@@ -2859,6 +2867,7 @@ func TestResourceChange_nestedSet(t *testing.T) { | |||
- { | |||
- mount_point = "/var/diska" -> null | |||
}, | |||
# (1 unchanged element hidden) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub won't let me properly bracket the unchanged lines here to make this a real "suggestion" but here's a proposed alternative expected output for the indentation I was talking about in my review comment:
# test_instance.example will be updated in-place
~ resource "test_instance" "example" {
~ ami = "ami-BEFORE" -> "ami-AFTER"
~ disks = [
+ {
+ mount_point = "/var/diska"
+ size = "50GB"
},
- {
- mount_point = "/var/diska" -> null
},
# (1 unchanged element hidden)
]
id = "i-02ae66f368e8518a9"
+ root_block_device {
+ new_field = "new_value"
+ volume_type = "gp2"
}
- root_block_device {
- volume_type = "gp2" -> null
}
}
(That was kinda awkward to edit in the GitHub comment box so I probably didn't get it all exactly right, but the indentation of the disks
contents is the main thing I'm getting at here.)
Thanks! The second example in your screenshot still seems a little off: the With that said, still potentially out of scope for what you're doing here so would be totally reasonable to just open a new issue to represent that and fix it up another time, but I'm hoping 🤞 that the pretty simple fix you found for the tuple/list case is also pretty simple for the object/map case. 😁 |
🤦 Thanks for catching that too. I had already merged this PR so I've opened #29986 to hopefully address it. The same issue looked to be the case for the nested single value, so I adjusted that too. |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Unchanged elements in nested attributes backed by sets were previously misrendered as empty objects. This PR removes the additional brackets and adds a count of unchanged elements, and secondarily fixes the indentation for these diffs.
Targeting 1.1 backport.
Screenshots
Before:
After: