4378: Make functions in well-known languages top-level concepts in the diff viewer

xelepart

What version are you running?

latest.

What's the URL of the page this enhancement relates to, if any?

the diff view.

Describe the enhancement and the motivation for it.

I often see a diff where I add a new function that is conceptually similar to the function below it in the code, and the diff viewer shows it as me inserting a new ending to the original function, and a new function with a new start, but the "same" end as the old function. This is incredibly confusing, and really doesn't make sense. The old function is completely unchanged, and there's a new function with a new name and similar code.

Given that the diff viewer seems to know what function we're in (from various other features), it seems like a simple step to have an option to treat functions as first class citizen, saying, essentially, that a given "piece" of the diff should, if at all possible, be contained within a single function.

A similar situation, where you're literally rewriting a function -- so you delete 2 helper functions, write 2 new helper functions, and change the logic of the public function to the new definition. The diff often ends up with this completely unreadable shotgun blast of red, green, yellow, and white, because of the "minimal diff" deal, where your one new function ends up being a semi-partial-replacement of the old function and one of the helpers, and the second half of that helper and other helper gets split up over the new helpers, which also show up as half a function of brand new code at the bottom. The final state of the code is completely unreadable, and it would make way more sense to see it on a per-function basis -- 2 deleted helpers, 2 new helpers, and the main function with an actual normal diff, completely bounded by the function's code block.

I could see this as a toggle, because I'm sure it would cause its own issues with certain types of changes (although, honestly, I can't actually think of one :) ) -- and there might need to be some special rules for function renaming, where if the old code had a function and the new code has a different function, rather than show a complete deleted function and a complete added function with a different name but all the same code, you'd need, like, a "90% similarity and neither has a function with that name in the other version means it's a rename" or you'd definitely get issues with that.

What operating system are you using? What browser?

Lots of them.

Please provide any additional information below.

I'd be happy to try to reproduce an example of a "bad diff view" and what I'd want it to look like (as screenshots), or even to put some time into learning the code for rb to try to help make the change if you would allow the feature but can't put the time into implementing it, but not sure when I'd have the time, which is one of the reasons I haven't just done it already. :D