k9 icon indicating copy to clipboard operation
k9 copied to clipboard

[WIP] Preliminary prototype for collapsed output

Open TheWebDevel opened this issue 4 years ago • 12 comments

Usecase: Difference between two structs. Assertion: assert_equal

Current Output: image

Collapsed Output: image

Method: String Iteration

Implementation:

  1. Computed the index of each occurrence with reference to (- or +). // [4, 5, 16, 17, 20, 21]
  2. I have a cur_index and a peek_index.
  3. If the difference between cur_index and peek_index is <= 5, I'll have those index and the intermediate values in the final collapsed output else I have a .... // [4, 5, 16, 17, 18, 19, 20, 21]

TheWebDevel avatar Jun 30 '20 14:06 TheWebDevel

might wanna have some more context around the changes and some hints around how much you skipped:

  A { 
    a: "Kelly"
... 20 lines hidden
    b: "blah blah"
-   c: 1
+   c: 2
    d: 4
... 20 lines hidden
}

aaronabramov avatar Jul 01 '20 15:07 aaronabramov

also. for the algorithm you probably want to do it at the same time you're constructing by keeping the unchanged_count counter as you're iterating through the diff, so you do everything in one pass. you might need some lookahead for that

aaronabramov avatar Jul 01 '20 15:07 aaronabramov

Yeah! I'm planning to do those things as well. As I said, this is a prelim first implementation prototype. I'll do that and let you know. :D Thanks!!

TheWebDevel avatar Jul 01 '20 15:07 TheWebDevel

Sure. I'll optimize the approach. So, can I proceed with the lookahead approach and extend it? I'll reply to this thread with the outcome of this ASAP. :D

TheWebDevel avatar Jul 01 '20 15:07 TheWebDevel

also, we should probably have some threshold. if i'ts lass than 30 lines we don't collapse anything

aaronabramov avatar Jul 01 '20 17:07 aaronabramov

Yeah!

TheWebDevel avatar Jul 01 '20 17:07 TheWebDevel

Update:

I found a way to collapse the output with single iteration.(Sorry about the colors, Need to find a way to put em back :P) image

Currently working on adding context to the diff. :))

TheWebDevel avatar Jul 05 '20 16:07 TheWebDevel

Ok, I integrated colored_diff with my logic for collapsing large output. It's so far so good.

What'll I do next?

  1. Going to write a lot of test cases.
  2. If all good, Implement into the library as a feature and submit for review

Here are some of the results: Struct diff image

Vector diff image

Thanks, @aaronabramov :D

TheWebDevel avatar Jul 08 '20 18:07 TheWebDevel

you might want some padding/context around changed lines!

right now you have

- 20
+ 3
... 10 lines collapsed

you probably want

- 20
+ 3
  4 // unchanged line
  5 // unchanged line
... 10 lines collapsed

aaronabramov avatar Jul 09 '20 16:07 aaronabramov

also need to find a good way to distinguish ... 10 lines collapsed from the acutual content. they're both grayed out right now :)

aaronabramov avatar Jul 09 '20 16:07 aaronabramov

Noted! :D

TheWebDevel avatar Jul 09 '20 16:07 TheWebDevel

PR: https://github.com/aaronabramov/k9/pull/61

TheWebDevel avatar Aug 02 '20 22:08 TheWebDevel