Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Create an actual diff of the formatting changes #19

Merged

Conversation

kmsquire
Copy link
Contributor

@kmsquire kmsquire commented Sep 10, 2020

I had to open a new pull request, but this one finally seems to be working as intended. In particular, it works with format-on-save turned on (which was broken with my last attempt).

Fixes #5. Fixes #12. Fixes #15. Fixes #16.

  • VSCode expects an array of TextEdit objects describing the
    formatting change to the file. The Python extension this code is
    based off of obtains a unified diff from the formatting tool, and
    constructs a TextEdit array from this. Because JuliaFormatter.jl
    does not produce diff output by default, we have to do it ourselves.
  • Instead of using file I/O, the Julia process doing the formatting
    reads julia code from stdin, and writes the formatted code to
    stdout. The typescript process then creates the requisite diff,
    formats it, and sends it back to vscode.
  • This code is somewhat inefficient in that the diff undergoes two
    transformations (unified diff to ParsedDiff to TextEdit array), so
    a future optimization would be to create a TextEdit array directly
    from the comparison of the two files. Alternatively,
    JuliaFormatter.jl could be updated to output a unified diff upon
    request.

@kmsquire kmsquire force-pushed the feature/create-proper-diff branch 4 times, most recently from 2ae6f7c to 7dba35c Compare September 10, 2020 21:40
* VSCode expects an array of `TextEdit` objects describing the
  formatting change to the file.  The Python extension this code is
  based off of obtains a unified diff from the formatting tool, and
  constructs a `TextEdit` array from this.  Because JuliaFormatter.jl
  does not produce diff output by default, we have to do it ourselves.
* Instead of using file I/O, the Julia process doing the formatting
  reads julia code from stdin, and writes the formatted code to
  stdout.  The typescript process then creates the requisite diff,
  formats it, and sends it back to vscode.
* This code is somewhat inefficient in that the diff undergoes two
  transformations (unified diff to ParsedDiff to TextEdit array), so
  a future optimization would be to create a TextEdit array directly
  from the comparison of the two files.  Alternatively,
  JuliaFormatter.jl could be updated to output a unified diff upon
  request.
@kmsquire kmsquire force-pushed the feature/create-proper-diff branch from 7dba35c to 05c528b Compare September 10, 2020 21:58
@kmsquire
Copy link
Contributor Author

The main thing still missing is a useful message when formatting fails. I haven't figured out how to capture and return that yet.

That said, this is working beautifully without that--I can make another PR if I figure out how to better handle errors.

@singularitti singularitti self-requested a review September 11, 2020 23:33
@singularitti singularitti self-assigned this Sep 11, 2020
@singularitti
Copy link
Owner

singularitti commented Sep 12, 2020

Thank you @kmsquire. I am no expert in TypeScript so it's so good that someone could help! I tried several examples and it seemed to work!

@singularitti singularitti merged commit c8564b0 into singularitti:master Sep 12, 2020
@samuela
Copy link

samuela commented Sep 12, 2020

Thank you so much @kmsquire! This improves my day-to-day experience with julia quite a bit!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants