Skip to content

fix(nix): drop none-ls formatter#1324

Merged
Uzaaft merged 3 commits intoAstroNvim:mainfrom
Mic92:ps/rr/fix_nix___drop_none_ls_formatter
Feb 2, 2025
Merged

fix(nix): drop none-ls formatter#1324
Uzaaft merged 3 commits intoAstroNvim:mainfrom
Mic92:ps/rr/fix_nix___drop_none_ls_formatter

Conversation

@Mic92
Copy link
Copy Markdown
Contributor

@Mic92 Mic92 commented Jan 19, 2025

nixd already provides formatting builtin:

https://github.com/nix-community/nixd/blob/2c25600cb9c91bc06fe8676c044814dc30435274/nixd/docs/configuration.md?plain=1#L62

📑 Description

ℹ Additional Information

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 19, 2025

Review Checklist

Does this PR follow the [Contribution Guidelines](development guidelines)? Following is a partial checklist:

Proper conventional commit scoping:

  • If you are adding a new plugin, the scope would be the name of the category it is being added into. ex. feat(utility): added noice.nvim plugin

  • If you are modifying a pre-existing plugin or pack, the scope would be the name of the plugin folder. ex. fix(noice-nvim): fix LSP handler error

  • Pull request title has the appropriate conventional commit type and scope where the scope is the name of the pre-existing directory in the project as described above

  • README is properly formatted and uses fenced in links with <url> unless they are inside a [title](url)

  • Entry returns a single plugin spec with the new plugin as the only top level spec (not applicable for recipes or packs).

  • Proper usage of opts table rather than setting things up with the config function.

  • Proper usage of specs table for all specs that are not dependencies of a given plugin (not applicable for recipes or packs).

@Uzaaft
Copy link
Copy Markdown
Member

Uzaaft commented Jan 20, 2025

We are currently avoiding nixfmt until it becoms stable. See the tracking issue: #883

@Mic92
Copy link
Copy Markdown
Contributor Author

Mic92 commented Jan 20, 2025

We have nixfmt in 24.11, so it is stable? Also this doesn't replace alejandra it let nixd handle the configuration. People can still configure nixd to use alejandra. It just sets the default.

@Uzaaft
Copy link
Copy Markdown
Member

Uzaaft commented Jan 20, 2025

We have nixfmt in 24.11, so it is stable? Also this doesn't replace alejandra it let nixd handle the configuration. People can still configure nixd to use alejandra. It just sets the default.

My PR sets the formatter as alejandra.As for the stability of nixfmt, check their github repo. They call it not yet stable. :)

@Mic92
Copy link
Copy Markdown
Contributor Author

Mic92 commented Jan 20, 2025

We have nixfmt in 24.11, so it is stable? Also this doesn't replace alejandra it let nixd handle the configuration. People can still configure nixd to use alejandra. It just sets the default.

My PR sets the formatter as alejandra.As for the stability of nixfmt, check their github repo. They call it not yet stable. :)

If nixd is active this doesn't work because nixd does the formatting not non-ls. So this is a no-op. Same is true for nil-ls. This pull request is not about alejandra vs nixfmt. You can still use alejandra after that.

@luxus
Copy link
Copy Markdown
Member

luxus commented Feb 2, 2025

thanks for the pr. whats will be the default formatter after the merge?

edit: so i guess it will be nixfmt or nixfmt-rfc-style depends what you have installed

luxus
luxus previously approved these changes Feb 2, 2025
Copy link
Copy Markdown
Member

@luxus luxus left a comment

Choose a reason for hiding this comment

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

looks fine, if people want to use something else then the default nixfmt, they can configure it

but the readme needs a update

@luxus luxus dismissed their stale review February 2, 2025 14:29

missing changes on the readme

@Uzaaft Uzaaft merged commit 17307e7 into AstroNvim:main Feb 2, 2025
@Zebradil
Copy link
Copy Markdown
Contributor

How to change the formatter now? I tried adding the following to the astrolsp config:

return {
  "AstroNvim/astrolsp",
  ---@type AstroLSPOpts
  opts = {
    ---@diagnostic disable: missing-fields
    config = {
      nixd = {
        formatting = { command = { "alejandra" } },
      },
    },
  },
}

But there seem to be no effect. Trying to format a nix file leads to the following error message in the lsp log (nixfmt isn't installed):

... "1583502: --> reply:textDocument/formatting(10) formatting nixfmt command exited with 65280, error: 3\n"

Though, it could be because nixd configuration is broken in general, as with vanilla astronvim configuration (from the template repo), with the nix pack enabled, I see the following error in the lsp log after opening a nix file:

... workspace/configuration: parse error expected object

@Uzaaft
Copy link
Copy Markdown
Member

Uzaaft commented Feb 26, 2025

How to change the formatter now? I tried adding the following to the astrolsp config:

return {
  "AstroNvim/astrolsp",
  ---@type AstroLSPOpts
  opts = {
    ---@diagnostic disable: missing-fields
    config = {
      nixd = {
        formatting = { command = { "alejandra" } },
      },
    },
  },
}

But there seem to be no effect. Trying to format a nix file leads to the following error message in the lsp log (nixfmt isn't installed):

... "1583502: --> reply:textDocument/formatting(10) formatting nixfmt command exited with 65280, error: 3\n"

Though, it could be because nixd configuration is broken in general, as with vanilla astronvim configuration (from the template repo), with the nix pack enabled, I see the following error in the lsp log after opening a nix file:

... workspace/configuration: parse error expected object

You can set it in your flake.nix

@Zebradil
Copy link
Copy Markdown
Contributor

According to nix-community/nixd#496, nixd doesn't support getting formatter configuration from flake.nix

@luxus
Copy link
Copy Markdown
Member

luxus commented Feb 26, 2025

what you wanna do? setting a different formatter? because nixd does have build in formating configuration and sets it to nix-fmt, if you want that, then just use the code from above

@Mic92 Mic92 deleted the ps/rr/fix_nix___drop_none_ls_formatter branch February 26, 2025 11:50
@Mic92
Copy link
Copy Markdown
Contributor Author

Mic92 commented Feb 26, 2025

@Uzaaft
Copy link
Copy Markdown
Member

Uzaaft commented Feb 26, 2025

what you wanna do? setting a different formatter? because nixd does have build in formating configuration and sets it to nix-fmt, if you want that, then just use the code from above

You are right. I gotta double check the behaviour in nixd some other day and come back to you.

@Zebradil
Copy link
Copy Markdown
Contributor

what you wanna do? setting a different formatter?

Yes, I wanted to use alejandra instead of the default nixfmt.

As @Mic92 pointed out, nixd can be configured, including the formatter. The problem is that my configuration doesn't have any effect.

It feels like there is a problem in the initial configuration process somewhere between astrolsp and nixd, but I don't possess skills to debug this further. Probably, this is not the right place for me for reporting this issue, I just thought that maybe some of you happen to use non-default formatter with nixd and knows how to configure it in astronvim. Where should I create an issue (astrolsp → nixd) instead?

@Uzaaft
Copy link
Copy Markdown
Member

Uzaaft commented Feb 26, 2025

what you wanna do? setting a different formatter?

Yes, I wanted to use alejandra instead of the default nixfmt.

As @Mic92 pointed out, nixd can be configured, including the formatter. The problem is that my configuration doesn't have any effect.

It feels like there is a problem in the initial configuration process somewhere between astrolsp and nixd, but I don't possess skills to debug this further. Probably, this is not the right place for me for reporting this issue, I just thought that maybe some of you happen to use non-default formatter with nixd and knows how to configure it in astronvim. Where should I create an issue (astrolsp → nixd) instead?

astrolsp is using the settings I apply to it, so it doesnt seem to be the issue.

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.

4 participants