Skip to content

Add nix fmt support#102

Merged
JojOatXGME merged 1 commit into
NixOS:masterfrom
Meallia:add-nix-fmt-support
Jul 5, 2026
Merged

Add nix fmt support#102
JojOatXGME merged 1 commit into
NixOS:masterfrom
Meallia:add-nix-fmt-support

Conversation

@Meallia

@Meallia Meallia commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

fixes #97 using suggested implementation

  • Add an option to Run formatter in file's parent directory. ( disabled by default )
  • Add a nix fmt suggestion for the format command
image

@Meallia Meallia force-pushed the add-nix-fmt-support branch from 303bfc7 to e3f6c26 Compare June 27, 2026 22:33

@JojOatXGME JojOatXGME left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I would merge the PR (assuming you don't object for whatever reason) and release the changes on the weekend.

I also want to thank you again for your contributions over last few months. 🚀

),
CommandSuggestionsPopup.Suggestion.builtin(
"<html>Use <b>nix fmt</b> from flake.nix</html>",
"nix --extra-experimental-features \"nix-command flakes\" fmt"

@JojOatXGME JojOatXGME Jun 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought 💭: Just wondering how reliable that will work as intended for different configurations of nix fmt. Specifically, I have recently used nixfmt-tree, and I think it will just reformat the entire repository if no argument is provided, not stdin as expected by this plugin.

Anyway, that should not block the merge of this PR. It would probably be noticeably more effort (and may include some "design-work") to make it work reliable across the board.

@Meallia Meallia Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, we always read the file content to pass it as stdin to the called process and get the formatted content from stdout. We could add an option to pass the file by path instead of content (and do the same for the formatted output).

I don't mind going the extra mile and implementing this as well, I think it would cover most cases.

But you can merge this as-is, I'll try to find some time to implement this after my vacations.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, makes sense.

Note that you will probably have to call FileDocumentManager.getInstance().saveDocument(document) or ManagingFS.getInstance().flushPendingUpdates(virtualFile) before starting the formatter. Not sure which one it is. This was recently announced at Async VFS Disk Writes: What Plugin Authors Should Check

@Meallia

Meallia commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

I also want to thank you again for your contributions over last few months. 🚀

You're welcome, thank you for the time and effort you put into maintaining this tool :-)

@JojOatXGME JojOatXGME merged commit 52b2638 into NixOS:master Jul 5, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support nix fmt as external formatter

2 participants