Skip to content
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

feat: improved merge conflict solver #139

Merged
merged 28 commits into from
Oct 2, 2024
Merged

Conversation

michal-futurice
Copy link
Contributor

No description provided.

@majori
Copy link
Member

majori commented Sep 10, 2024

I noticed that in this case the first line foo is omitted from the diffs. I wonder if this is an UI bug
image

Copy link
Contributor Author

@michal-futurice michal-futurice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far! I was able to understand everything. I added some small comments, but these are just opinionated and nothing very important. Just see what you think.

I also think I see one bug (same as Antti?) but I'll make a separate comment for it.

case tea.KeyPgDown:
diffConflictCount := len(m.diff.GetUnifiedDiffConflictIndices())
m.currentDiffIndex = min(diffConflictCount-1, m.currentDiffIndex+1)
m.viewport.YOffset = m.diff.GetUnifiedDiffConflictIndices()[m.currentDiffIndex] - 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetUnifiedDiffConflictIndices returns zero-based line indices. So I'd like to just make sure that a possible -1 YOffset is ok and means something. I do not know the library.

pkg/ui/conflict/conflict.go Outdated Show resolved Hide resolved
pkg/ui/conflict/conflict.go Show resolved Hide resolved
} else {
s.WriteString("keep")
s.WriteString("diff file written")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just about the strings: should we use either present tense or past tense for all 3 options? I.e. "write diff file" here, if we would want to align to "use new" etc., or the other way around?

@@ -66,16 +145,20 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.submitted = true
return m, tea.Quit
case tea.KeyRight:
m.answer = true
m.resolution = min(m.resolution+1, 3)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should try to avoid hardcoding the numbers 3 here and also 1 on line 150 below. This might turn hard to manage if e.g. choices are added or removed. And also one way to sense that something might be off now is by noticing that the UseDiffFile constant is not used. We could replace this 3 with UseDiffFile and the 1 on line 150 with UseOld, but it still makes changes hard...

Should we maybe add something like var choices = [...]int{UseOld, UseNew, UseDiffFile} after the 3 constants at the top and then use this array to drive at least this navigation here, maybe some other similar place, too? Optimally we would then also refactor footerView to use this array to produce the resolutionSelector, for example. Ok, this might be too complicated all in all. Maybe we can make these changes if more options are ever added... not sure.

@michal-futurice
Copy link
Contributor Author

I think the first line of the diff might not be showing now - what Antti also noticed (at least). I added this brutal println to the code to dump the raw diff and the first Blah line preceding the +Bleh is visible in the raw, but not in the UI. Not immediately sure where the effect originates.

Screenshot 2024-09-10 at 14 01 08

The UI also feels as if there were more empty lines at the end than there actually are in the diff (can be arrowed down several lines more that where the file ends). This is not a show-stopper, but in some situations might be confusing.

@michal-futurice
Copy link
Contributor Author

Also, should the 100% here be in a complete rounded box, or is it by design that the top is an "artistic" hook like this? Doesn't look entirely bad, but not sure what was intended :) . Is it only on my machine perhaps.

Screenshot 2024-09-10 at 14 11 44

@michal-futurice
Copy link
Contributor Author

One more usability thing came to mind as I was testing (not a show stopper): currently currentDiffIndex is independent from navigating line-by-line. So if I have a file with say 3 conflicts, and I first manually arrow down past the 2nd conflict, so that it disappears above the viewport, then pressing PgDown for the first time at this moment actually takes me up, which is maybe counter-intuitive. I would like to now go down to the next conflict below where I am.

Also it's not possible to PgDown to the first conflict in the file, because the field is already initialised to 0, so first PgDown takes the user to 1'th i.e. second conflict.

Maybe a solution would be to have currentDiffIndex be an *int, with a possibility for nil value, which would be the starting value. Then if PgUp / PgDown is pressed and currentDiffIndex == nil then the UI would infer which is the closest conflict to where we are now, and only then go the previous / next one. At the same time pressing up / down arrows, i.e. manual line-by-line navigation, could always reset currentDiffIndex to nil.

Bit intricate and there might be a better way still... I'm just making this up now. It's maybe half bug half missing feature now. No strong opinions.

@majori majori changed the title Feat/merge conflict solver feat: improved merge conflict solver Sep 11, 2024
@Katajisto Katajisto force-pushed the feat/merge-conflict-solver branch from d7cf914 to 9c15295 Compare September 23, 2024 09:42
pkg/ui/conflict/conflict.go Outdated Show resolved Hide resolved
pkg/ui/conflict/conflict.go Outdated Show resolved Hide resolved
Comment on lines 131 to 132
oldStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#FF0000"))
newStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#00FF00"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder is the raw green and red best options here. For example there are "common" green and red used throughout the code

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed them to match these, I am not sure if it made it look better but consistency within the app is nice to have.

}

func readStringFromFile(name string) (string, error) {
fileBytes1, err := os.ReadFile(name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, you can use embed package to read files easily to a variable. It would work great in this case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL, did not know about this package 👍 . I now rewrote this to use it with an FS. I'm not sure is that what you had in mind. This test is parametrised theoretically (although in the end there's only 1 test case now), so the completely static embedding to a string var would probably not work here, or I haven't figured out how. But this should be already a bit more compile time I guess, so probably better 👍 .

Let me know if you had some smarter way to use it in mind!

I've been sold ~100% in the meantime and I might reply with a delay & no longer be able to do larger changes.

@majori majori linked an issue Sep 24, 2024 that may be closed by this pull request
@michal-futurice
Copy link
Contributor Author

Had a moment to read the code again and test - looks good! 👍 The only issue I found is that the yellow does not work so well with the light color scheme of the terminal. Maybe some shade of gray would work for both?

Screenshot 2024-09-30 at 7 36 17

@Katajisto Katajisto force-pushed the feat/merge-conflict-solver branch from 672700c to fc057e2 Compare October 2, 2024 08:22
@Katajisto Katajisto merged commit eb4b162 into main Oct 2, 2024
6 checks passed
@Katajisto Katajisto deleted the feat/merge-conflict-solver branch October 2, 2024 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improved merge conflict solver when upgrading recipe
3 participants