Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maven IDE hook for jj fix #2424

Open
victornoel opened this issue Feb 18, 2025 · 7 comments
Open

maven IDE hook for jj fix #2424

victornoel opened this issue Feb 18, 2025 · 7 comments

Comments

@victornoel
Copy link

Hi,

I am trying to setup jujutsu so that it runs spotless (configured using the maven plugin in my repository) when using jj fix, see https://jj-vcs.github.io/jj/latest/cli-reference/#jj-fix.

The problem is that the requirement from jujutsu is that the tool that does formatting should respect the following rule:

The external tools must accept the current file content on standard input, and return the updated file content on standard output. A tool's output will not be used unless it exits with a successful exit code. Output on standard error will be passed through to the terminal.

Would that be something that could be added to spotless?

Thanks!

@nedtwigg
Copy link
Member

Spotless Gradle supports this, but the Maven support is immature. @SapiensAnatis has made some progress here.

@nedtwigg nedtwigg changed the title Feature for piping files to spotless instead of in-place modification maven IDE hook for jj fix Feb 18, 2025
@SapiensAnatis
Copy link

I didn’t write the IDE hook to be clear, but it sounds broadly like what you are looking for.

If you use these arguments: https://github.com/SapiensAnatis/vscode-spotless-maven/blob/5cb5fa5a1cc444e47aa50e33547b2ffefdf56dec/src/maven/basicMavenExecutor.ts#L28

You will get a process that takes a document on stdin and then returns on stderr IS CLEAN / IS DIRTY and on stdout the formatted document.

The only problem is I can’t remember if you get the formatted document on stdout if Spotless returns IS CLEAN. In the vscode extension we just return ‘no changes’ if we get that back.

@victornoel
Copy link
Author

Hey @SapiensAnatis @nedtwigg thank you for the feedback, I will do a bit of experimentation with that to see how it behaves and come back here to share my findings!

@victornoel
Copy link
Author

I can already share this:

  • on "IS CLEAN", the file is not outputted indeed, that could be a problem for jj fix but I'm sure I will find a temporary workaround until we decide here if we should change the behaviour or not
  • on "IS DIRTY" it looks like it's doing exactly what I am expecting
  • in the long run there will also be the concern of performance
    • mvn is slow to startup, so for tens of file it's going to be long to run… well, it's always better than doing it by hand 😃
    • I'm not sure how this can be solved in practice: I mean, spotless already starts a separate npm process to be able to format multiple files faster, now will we need a separate mvn process to submit the files to format? 😅

@SapiensAnatis
Copy link

Performance wise I think the way forward is to use mvnd which runs as a daemon and is much faster for ad-hoc formatting. However it doesn’t seem to be compatible with the IDE hook at the minute, I’ve raised a few issues over there so hopefully those will be fixed soon!

@victornoel
Copy link
Author

victornoel commented Feb 20, 2025

I did a few tests with mvnd using both -DspotlessFiles and -DspotlessIdeHook (without stdin/out) and performances are still not great

It's taking something like 2.8sec with -DspotlessFiles and 3.8sec with -DspotlessIdeHook. The IDE Hook actually restarts the npm process every time ^^

running spotless:apply on ALL my files takes the same time btw, so the overhead is somewhere else, which means there is maybe some margin for improvement on the spotless side :)

@SapiensAnatis
Copy link

Oh the IDE hook is really only for a single file (hence IDE). On a single file it takes about 0.4s for me (assuming the daemon is warm) but if you are formatting your entire solution it will probably be slower.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants