Repository navigation
Add initial first-class support for nix fmt - #104
Draft
JojOatXGME wants to merge 2 commits into
Draft
JojOatXGME wants to merge 2 commits into
JojOatXGME wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is my attempt to resolve #97.
This PR takes initial steps for first-class support of
nix fmt, together with a new option “Use CLI argument” for custom commands.@Meallia I am mentioning you because you worked on #102, and because you also considered looking into this topic in the future. Feel free to comment if you have any suggestions, but no pressure.
Approach and remaining problems
Unfortunately, my testing shows some problems with the current implementation. Here is my approach:
nix fmt {path-to-file}VfsUtil.markDirtyAndRefreshto inform IntelliJ that the file has changedThis leads to the following dialog if the user continuous to type after string the formatter:
I currently see two potential solutions to address these problems:
Rely on
treefmt-specific command line arguments:nix fmt -- --stdin -- {path-to-file}Copy the formatted file, and pass the new temporary file to the command instead of the original.
Afterward, copy back the formatted changes from the temporary file to IntelliJ.
Not sure if there is a third viable approach.
I also noticed that the current performance is rather bad. Running the formatter from IntelliJ takes much longer then calling in from the terminal. I have not yet profiled the issue.
Future Work
Beside the previously mentioned issues, there are some open topics which could be discussed in the future if the initial implementation has been released:
nix fmtis often configured to also handle other types of files, not just*.nix. It might be valuable to enable the external formatter for these files as well. The main challenge would be how to figure out from the plugin which files can be formatted by the current configuration ofnix fmt.IntelliJ cancels the formatting task if it takes more than 30 seconds. This can easily happen if the formatter is not yet available and has to be built (or downloaded). We should try to figure out if we can find a way around this timeout.
When running the formatter,
stderris currently only shown to the user once the process returns a non-zero exit code. However, for lengthy build processes, we should try to make the progress visible to the user.Screenshots
Here are two screenshots of the new settings page: