Skip to content

nixd times out on large files #691

@podocarp

Description

@podocarp

Describe the bug

I'm using nvim. I'm testing by just directly calling vim.lsp.buf.format({}).
On a large file I tested (1428 lines) I get

[LSP][nixd] timeout

On a smaller flake file I tested (186 lines) the command works fine and I can see that the file has been reformatted.

Logs (Required)

[ERROR][2025-05-23 11:38:20] ...p/_transport.lua:0	"rpc"	"nixd"	"stderr"	"I[11:38:20.409] 74232: "
[ERROR][2025-05-23 11:38:20] ...p/_transport.lua:0	"rpc"	"nixd"	"stderr"	"<-- textDocument/formatting(18)\n"
[ERROR][2025-05-23 11:38:21] ...p/_transport.lua:0	"rpc"	"nixd"	"stderr"	"I[11:38:21.438] 74232: <-- $/cancelRequest\nI[11:38:21.438] 74232: unhandled notification $/cancelRequest\n"

Configuration
I'm using nixvim, but its a super simple config.

nixd = {
  enable = true;
  settings.nixd = {
    formatting.command = [ "nixfmt" ];
  };
};

To Reproduce
On a flake.nix file from nixpkgs, 195 lines

Screen.Recording.2025-05-23.at.11.46.13.AM.mov

On the all-packages.nix file from nixpkgs, 18k lines

Screen.Recording.2025-05-23.at.11.48.34.AM.mov
 time nixfmt all-packages.nix

real    0m0.583s
user    0m0.537s
sys     0m0.029s

This does not exceed the nvim format default timeout of 1s.

Expected behavior
It not to time out
Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions