1. 19

  2. 2

    I wonder if you could diff two ASTs easily by converting them to a gron-like representation: a list of (path, node) pairs. Unlike text, there are no parens/braces to mess up. And unlike(?) a tree, it would be easy(?) to tell when a subtree moved, because it looks just like a chunk of lines that moved.

    1. 4

      If you mean what I think you mean, it wouldn’t work well. For example, say you take the example from the gron page:

      json[0].commit.author = {};
      json[0].commit.author.date = "2016-07-02T10:51:21Z";
      json[0].commit.author.email = "mail@tomnomnom.com";
      json[0].commit.author.name = "Tom Hudson";

      and wrap the commit in a… commitGroup or something:

      json[0].commitGroup[0].commit.author = {};
      json[0].commitGroup[0].commit.author.date = "2016-07-02T10:51:21Z";
      json[0].commitGroup[0].commit.author.email = "mail@tomnomnom.com";
      json[0].commitGroup[0].commit.author.name = "Tom Hudson";

      Then the tree diff should be a single edit: “insert commitGroup as a parent of commit”, but the gron-diff shows that every line changed.

      My understanding is that computing tree diffs is, unfortunately, just plain-out computationally difficult. Cubic time in the size of the tree or something.

      1. 3
        1. 2

          Nope! I’m glad that exists, hopefully structured diffs are the future!

          You’ll notice that the first listed known problem is “performance”. I remember talking to a Github employee at a conference years ago about structured diffs, who said that was a big obstacle and they had ideas for clever heuristics to make it faster. I wonder if that ever went anywhere (for all I know it could be related to difftastic).

          (As an aside, I really love when a project points out both their strengths and weaknesses… you know it has some weak points, so it’s a question of whether they’re going to tell you or you have to find out the hard way.)

    2. 1

      Big 👍👍 to atomic renames, and this whole concept in general. Unison language seems to be related, although I don’t know if they’ve implemented collaboration / edit-merging yet.

      I hope to eventually have similar features in a structural frontend for Dawn, though that’s in the distant future—text is sufficient for the time being, and it’s already an insanely ambitious project (for reasons I have yet to fully explain).