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

nil.formatting.command setting does not work #21680

Closed
1 task done
caiigee opened this issue Dec 7, 2024 · 4 comments
Closed
1 task done

nil.formatting.command setting does not work #21680

caiigee opened this issue Dec 7, 2024 · 4 comments
Labels
documentation [core label] nix Nix configuration support setting Feedback for preferences, configuration, etc

Comments

@caiigee
Copy link

caiigee commented Dec 7, 2024

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

I have declared the Nix language extension in my home-manager options for Zed:

  programs.zed-editor = {
    enable = true;
    extensions = [
      "html"
      "toml"
      "nix"
      "ron"
      "git-firefly"
    ];

I have also declared nil and nixd as extraPackages for Zed:

    extraPackages = with pkgs; [
      nixd
      nil
      alejandra
    ];

Now, when I edit nix files all the syntax highlight and suggestions and all that works. However, when I try to format using Ctrl+Shift+i it gives me an error saying:

2024-12-07T11:00:47.985513761+01:00 [ERROR] Formatting failed: failed to format via language server: No formatter configured. Set the nil.formatting.command LSP server setting.
2024-12-07T11:00:47.985598351+01:00 [ERROR] failed to format via language server

Caused by:
    No formatter configured. Set the nil.formatting.command LSP server setting.

So, that is exactly what I tried:

      lsp = {
        nil = {
          formatting = {
            command = "alejandra .";
          };
        };
      };

However, the above setting doesn't seem to do anything. Did I do something wrong? Is there another that I should have declared?

Environment

Zed: v0.163.2 (Zed)
OS: Linux Wayland nixos 25.05
Memory: 14.9 GiB
Architecture: x86_64
GPU: AMD Radeon 680M (RADV REMBRANDT) || radv || Mesa 24.2.6

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

No response

@apekros

This comment has been minimized.

@thoward27
Copy link

Just in case this is helpful to anyone, here's a working zed configuration stanza for the nil lsp:

  "lsp": {
    "nil": {
      "initialization_options": {
        "formatting": {
          "command": ["nixfmt"]
        }
      }
    }
  }

@uncenter
Copy link
Contributor

This works for me (simplified):

{
  programs.zed-editor = {
    enable = true;

    extensions = [
      "nix"
    ];

    userSettings = {
      languages = {
        Nix = {
          language_servers = [
            "nil"
            "!nixd"
          ];
          formatter = {
            external = {
              command = "nixfmt";
            };
          };
        };
      };
    };
  };
}

@caiigee caiigee closed this as completed Dec 16, 2024
@notpeter
Copy link
Member

Would love to document any/all of these things in the zed-extensions/nix README.md. Happy to review PRs!

@notpeter notpeter added documentation [core label] setting Feedback for preferences, configuration, etc nix Nix configuration support and removed bug [core label] triage labels Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation [core label] nix Nix configuration support setting Feedback for preferences, configuration, etc
Projects
None yet
Development

No branches or pull requests

5 participants