Coder Social home page Coder Social logo

Comments (6)

tomjaguarpaw avatar tomjaguarpaw commented on June 12, 2024 1

I see, thanks. For me an inline view is essential so I guess difft won't be a good fit for me. Still, I'm happy to have tried it out. Thanks for writing it!

from difftastic.

Wilfred avatar Wilfred commented on June 12, 2024

Why would you expect line 2 to show as green? As far as I can see there are only removals on that line.

from difftastic.

tomjaguarpaw avatar tomjaguarpaw commented on June 12, 2024

Hi Wilfred, thanks for your reply. Perhaps this is an XY problem so let me put it another way.

The standard diff tool on my system has the following property: from the content of test1.hs and the output of diff test1.hs test2.hs I can deduce the content of test2.hs. This seems to me to be the most essential property of a diff tool. Specifically, if test1.hs contains

example cond =
  print (if cond then 0 else 1,
         if cond then 2 else 3
        )

and the output of diff /tmp/test1.hs /tmp/test2.hs is

2,3c2,4
<   print (if cond then 0 else 1,
<          if cond then 2 else 3
---
>   print (if cond
>          then (0, 2)
>          else (1, 3)

then I can deduce the content of test2.hs by replacing test1.hs's lines 2 and 3 with the three lines in the second section of the diff output. However, I don't understand how the same deduction is possible using the output of difft. Perhaps I'm just unaware of the correct interpretation of the output format (or perhaps it's not supposed to be possible). Let's consider (for simplicity) the case without color, that is

difft --display=inline --color=never /tmp/test1.hs /tmp/test2.hs

The output is

/tmp/test2.hs --- Haskell
1    example cond =
2      print (if cond then 0 else 1,
3             if cond then 2 else 3
   3          then (0, 2)
   4          else (1, 3)
   5         )

How can I deduce the content of test2.hs knowing just the content of test1.hs and the output of difft? Put another way, if I were going to write the equivalent of patch for difft, what algorithm would I use to determine the effect of difft's output on the original file? The difficulty here is that I don't know how I could determine that line 2 of test2.hs is

  print (if cond

from difftastic.

Wilfred avatar Wilfred commented on June 12, 2024

Difftastic does not aim to provide a valid patch. There's a brief discussion in non-goals here: https://github.com/Wilfred/difftastic#non-goals

Difftastic works out the the relationship between the two files, and highlights the parts of the AST that don't match. That's why it considers the following JSON files the same:

[100, 200, 300]
[100,
 200,
 300]

It might be interesting to add a mode that shows a traditional patch with the AST diff elements highlighted. This would be tricky because some line-based patches are not syntactic changes (like the example above).

from difftastic.

tomjaguarpaw avatar tomjaguarpaw commented on June 12, 2024

Sure, I don't actually want to apply the output of difft as a patch. I'm clearly explaining myself poorly. The fact that equivalent ASTs compare as equal is important information for me to take into account, thanks. I'll try again.

I'm asking whether, in principle, knowing the content of test1.hs and the output of difft test1.hs test2.hs, I should be able to deduce the content of test2.hs, modulo AST equivalence? That seems to me to be an essential property of a diffing tool, but it seems to me that difft doesn't have that property (example given above).

If it is a goal, does difft actually satisfy it? If not, then presumably it's a bug. If so, then can you explain how? I don't understand how to deduce the contents of test2.hs in the example above.

from difftastic.

Wilfred avatar Wilfred commented on June 12, 2024

Yep, you should be able deduce the content of the second file modulo AST equivalence.

The inline display is harder to read, and I rarely use it. This is one of the inline display failure cases: when the line-based diff and AST diffs consider the first change to be in different lines, it's hard to render in a comprehensible way.

Here's the default display:

Screenshot from 2023-12-30 11-26-49

From this, I can deduce that I can transform the first file into the second by opening a parenthesis before the 0, removing the else 1 to get me up to the comma, and so on.

from difftastic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.