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

null-ls: add ability to specify custom servers #97

Closed
seghers opened this issue Dec 30, 2022 · 4 comments
Closed

null-ls: add ability to specify custom servers #97

seghers opened this issue Dec 30, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@seghers
Copy link

seghers commented Dec 30, 2022

  programs.nixvim = {
      plugins.null-ls = {
        enable = true;
        sources.formatting.black.enable = true;
        sources.formatting.prettier.enable = true;
        sources.diagnostics.shellcheck.enable = true;
      };

      extraPlugins = with pkgs.vimPlugins; [
        null-ls-nvim
      ];
      extraPackages = [
        pkgs.shfmt
      ];

      extraConfigLua = ''
        require('null-ls').setup {
          sources = {
            require('null-ls').builtins.formatting.shfmt.with({
              -- Indent with 4 spaces, simplify the code, indent switch cases,
              -- add space after redirection
              extra_args = { '-i', '4', '-s', '-ci', '-sr' },
            }),
          },
        }
    '';
  };

When I open a shell script and try to format it, it doesn't work.
The null-ls formatter isn't recognized.
Error: [LSP] Format request failed, no matching language servers.
I do see the diagnostics from shellcheck.
I think this is because inside nvim/init.lua: I see the nixvim generated null-ls generated way before the one I set in extraConfigLua, and only the first is executed...?
For now I do all null-ls inside extraConfigLua, without plugins.null-ls.
Could we add something to insert lua inside null-ls? plugins.null-ls.manualsources ?

When I do everything inside extraConfigLua it does work.

  programs.nixvim = {
     extraPlugins = with pkgs.vimPlugins; [
        null-ls-nvim
     ];
      extraPackages = [
        pkgs.shfmt
      ];

      extraConfigLua = ''
        require('null-ls').setup {
          sources = {
            require('null-ls').builtins.formatting.shfmt.with({
              -- Indent with 4 spaces, simplify the code, indent switch cases,
              -- add space after redirection
              extra_args = { '-i', '4', '-s', '-ci', '-sr' },
            }),
            require("null-ls").builtins.formatting.prettier,
            require("null-ls").builtins.formatting.black,
            require("null-ls").builtins.diagnostics.shellcheck
          },
        }
    '';
  };

I could make a pull request to just add shfmt to nixvim, but I don't see a way to configure the extra_args inside plugins.null-ls.

@seghers seghers added the enhancement New feature or request label Dec 30, 2022
@pta2002
Copy link
Collaborator

pta2002 commented Dec 30, 2022

Yeah you're right that what you're doing won't work - the solution at the moment would be to either patch nixvim to add shfmt, or to just skip the module for null-ls.

Of course, the proper solution is to add the ability to add custom packages to null-ls without patching NixVim, so I'll change this issue to reflect that so I can add that functionality.

@pta2002 pta2002 changed the title How could I add a null-ls source and keep using other sources through nixvim. null-ls: add ability to specify custom servers Dec 30, 2022
@Alexnortung
Copy link
Contributor

I think there is a pretty easy fix for this. Just include an extraOptions options, so you can configure everything if nixvim doesn't have the options for it.

Related #30

@GaetanLepage
Copy link
Member

Is this issue now fixed ? (thanks to #251)

@GaetanLepage
Copy link
Member

As null-ls has been archived we will not spend time enhancing our current implementation.
If you find any bug/problem with the way we support null-ls now, please feel free to re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants