Fix race conditions with new spotless API#10
Conversation
The new spotless API allow us to use the stdin, stdout & stderr streams without ever writing to disk. This solves all of the race conditions.
In some cases vscode will cancel a formatting operation. See: https://code.visualstudio.com/api/references/vscode-api#cancellation-tokens These changes are required to correctly test the formatting behaviour.
472c9dd to
d07d1b9
Compare
|
Tests are failing in Windows. I've replicated this behaviour when running the extension in Windows 10. Attempt to debug by using the gradle wrapper, as outlined in this comment: diffplug/spotless#568 (comment) After some initial testing, it is working as expected using the gradle wrapper: gradlew.bat spotlessApply -PspotlessIdeHook=C:\Users\Richard\Desktop\vscode-spotless-gradle\test-fixtures\gradle-project\src\main\java\gradle\project\App.java -PspotlessIdeHookUseStdIn -PspotlessIdeHookUseStdOut --quiet < stdin.txt...with the following contents in stdin.txt: package gradle.project;public class App {public static void main(String[] args) {System.out.println("app");}}Using spotless-gradle version 13700cbe45344f45cbef79cbba94aec6724757f8 (latest) Next steps: use latest spotless-gradle version in vscode, check the windows paths aren't being munged. I've discovered the issue lies within vscode-gradle and how i'm chunking stdout based on newlines. Not sure the best approach to fixing this but at least it's fixable and not a problem with gradle or spotless-gradle. |
|
Created a bug report in |
I've had great difficulty find a nice way to test cancelled formatting, so this will have to do.
62507ad to
7553c06
Compare
c0da43b to
dbd48d1
Compare
It's not a known language identifer
It's not a known language type
This extension provides a bunch of language identifiers which we don't want when running tests
For some reason the kotlin formatting timeouts on MacOS in CI
b3e5802 to
b4ba336
Compare
|
@nedtwigg This PR is pretty much ready to go. It was more work than I expected. I had all types of issues with CI, as usual haha. Integration tests (for Linux, Windows & MacOS) are now passing consistently. Now I just need diffplug/spotless#568 merged and a new version released before I can release these changes. I had to make a bunch of a changes to |
|
Now published in Spotless |
|
LGTM! |
|
Released with 0.1.0 🎉 |
This PR fixes all the issues with race conditions, as outlined in this gist.
At a high-level, the formatting no longer relies on disk operations. Instead standard streams (stdin, stdout, stderr) are used to pass document text to spotless and get back formatted text. Various changes were made to vscode-gradle (microsoft/vscode-gradle#348) and spotless (diffplug/spotless#568) to support this. This also means we can format dirty files without saving them.
TODO
vscode-gradlepackage releasedAdd tests for formatting clean filesAdd tests for massive java filesTests would be too flaky. I've added an example of a massive file and have manually tested the formatting on it.Fix activation events (*.gradle instead of gradlew)-PspotlessIdeHookUseStdin -PspotlessIdeHookUseStdOutparamsSupersedes #5