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

WIP/RFC: dynamic_command is now async, and runs immediately when opening buffers #197

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jfly
Copy link
Collaborator

@jfly jfly commented Oct 11, 2024

This implements #193.

This is incomplete, which is why I've marked it as draft. It's also stacked on top of #192, and includes the commits from that PR. Just ignore the first 2 commits in this PR and focus on the last one ("WIP/RFC: dynamic_command is now async, and runs immediately when opening buffers").

I've redefined dynamic_command to be an async
function, but I haven't actually updated all the builtins accordingly. I
have updated nix_flake_fmt to demonstrate the idea.

If folks like the direction I'm going with this, I'll polish up
the PR so all dynamic_commands are async, and I'll get the tests
passing.

nvim-2024-10-11_16.00.32.webm

I'm building a [`nix fmt`](https://nix.dev/manual/nix/latest/command-ref/new-cli/nix3-fmt) formatter.

The tricky thing about `nix fmt` is that for nontrivial projects,
the entrypoint (`nix fmt`) can be slow enough to be a bad experience to
run on every save, and can even trigger [neovim's lsp
timeout](https://github.com/nvimtools/none-ls.nvim?tab=readme-ov-file#i-am-seeing-a-formatting-timeout-error-message).
It's not the that underlying formatter it invokes are slow, it's that it
can take 1-2 seconds for nix to evaluate the `flake.nix` and determine
what command `nix fmt` should run under the hood.

Since the underlying command shouldn't change very often for a given
project, I feel like it would be reasonable to cache this result per
project, hence this new `by_bufroot` callback.
This uses `nix fmt` under the hood. I introduced some caching make it
performant, as `nix fmt` can take a little while to evaluate all your
nix code to figure out the formatter entrypoint.
…ening buffers

This implements <nvimtools#193>.

This is incomplete: I've redefined `dynamic_command` to be an async
function, but I haven't actually updated all the builtins accordingly. I
have updated `nix_flake_fmt` to demonstrate the idea.

If folks like the direction I'm going with this, I'll polish up
the PR so all `dynamic_command`s are async, and I'll get the tests
passing.
@jfly
Copy link
Collaborator Author

jfly commented Oct 11, 2024

@Lassulus, FYI with this change I think slow nix flake eval time is basically unnoticeable =)

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.

1 participant