Feature #52

Improved Diff Scanner

Added by Kornelius Kalnbach almost 2 years ago. Updated 3 months ago.

Status:Feedback Start:09/25/2008
Priority:Normal Due date:
Assigned to:Kornelius Kalnbach % Done:

80%

Category:Scanner improvements
Target version:1.0 RC1

Description

A good diff Scanner should not only higlight the annotations created by diff, but also the code inside it. This should be possible because every part of a diff starts with the names of the files that are diffed.

intelligent-diff-highlighting.png (89 KB) Kornelius Kalnbach, 03/31/2010 12:28 am


Related issues

related to CodeRay - Feature #22: Simple Diff Scanner Closed 08/04/2008
related to CodeRay - Feature #199: Use Alpha blending for HTML styles Closed 02/15/2010
related to CodeRay - Feature #227: Inline Diff Highlighting Feedback 05/04/2010
related to CodeRay - Feature #222: Tokens#split_into_lines New 04/02/2010

Associated revisions

Revision 519
Added by Kornelius Kalnbach 5 months ago

Improved Diff scanner - yay! Finally! Still imperfect, but works (see #52).

History

Updated by Kornelius Kalnbach 8 months ago

  • Target version changed from 1.0 RC1 to 1.1

Updated by Kornelius Kalnbach 8 months ago

  • Category changed from Scanner requests to Scanner improvements

Updated by Kornelius Kalnbach 7 months ago

It turns out that a simple, line-based version was quite easy to implement. Commit follows.

Updated by Kornelius Kalnbach 7 months ago

We need nicer token color blending for this (eg. strings on insertions), as the new Alpha style provides.

Updated by Kornelius Kalnbach 7 months ago

  • Target version changed from 1.1 to 1.0 RC1

Updated by Kornelius Kalnbach 5 months ago

It determines the language based on the filename in the header, and looks awesome - see screenshot.

The only thing missing for now is Tokens#split_into_lines.

Updated by Kornelius Kalnbach 5 months ago

Maybe what we need is more like Tokens#each_line?

Updated by Eric Thomas 4 months ago

Rather than having it as a title text would it be possible for it to just highlight the change similar to the way github does it: http://github.com/rails/rails/commit/4e75cc59e70947b794c96894d39c015f9e1cb96c#L0L143
?

Updated by Kornelius Kalnbach 4 months ago

That might be possible, but it would be necessary to implement a diff mechanism into the scanner. Also, with the new code-inside-diff highlighting, the change could begin or end in the middle of a token that is served by another scanner, which makes it more complicated.

I think this should be another ticket. Can you open one?

Updated by Kornelius Kalnbach 4 months ago

I really like your idea! It has to be carefully combined with other features of CodeRay. Most importantly, it may not be a good idea to highlight the changed portion with a background tint, like github does - because, with the new file-based highlighting inside the diff code, we already have a tint for the changed line (red or green) and possibly for strings, strings inside strings, and so on. Using the new Alpha style (which uses CSS 3 colors) it's technically possible to stack three or more of those transparent background colors, but I think there's a better way.

This way is using boxes. A thin red or green border around the change could highlight it without changing the background color. I haven't been able to find a nice diff library for Ruby, though. Diff-LCS and differ don't seem work with strings like this.

Updated by Kornelius Kalnbach 4 months ago

Looking at GitHub's diff highlighting, I noticed several things:

  • It doesn't highlight inline changes in gists, only for changesets.
  • Only single-line changes seem to be handled this way. If a change covers two or more consecutive lines, it doesn't highlight the changes inline.
  • There seems to be only one highlighted part per line, and it's determined by matching the lines from the beginning and from the end until a difference is detected. It's a quite simple algorithm, yet quite useful, as you pointed out.

Updated by Eric Thomas 4 months ago

Kornelius Kalnbach wrote:

That might be possible, but it would be necessary to implement a diff mechanism into the scanner. Also, with the new code-inside-diff highlighting, the change could begin or end in the middle of a token that is served by another scanner, which makes it more complicated.

I think this should be another ticket. Can you open one?

New ticket here: #227

Updated by Kornelius Kalnbach 3 months ago

  • Status changed from New to Feedback
  • % Done changed from 60 to 80

The new Diff scanner now has all the features I planned, but it'll need more testing.

Also available in: Atom PDF