nix-community / nixvim

Configure Neovim with Nix! [maintainer=@GaetanLepage, @traxys, @mattsturgeon, @khaneliman]
https://nix-community.github.io/nixvim
MIT License
1.59k stars 249 forks source link

[PLUGIN REQUEST] vim-helm + Helm LSP #989

Open mnaser opened 7 months ago

mnaser commented 7 months ago
Field Description
Plugin vim-helm + helm-ls
Homepage https://github.com/towolf/vim-helm + https://github.com/mrjosh/helm-ls
Nixpkgs https://search.nixos.org/packages?channel=23.11&show=vimPlugins.vim-helm&from=0&size=50&sort=relevance&type=packages&query=vim-helm + https://search.nixos.org/packages?channel=23.11&show=helm-ls&from=0&size=50&sort=relevance&type=packages&query=helm-ls

Extra Information

This would be super neat to have! Thank you for the awesome project.

samos667 commented 1 month ago

Hi, there is a common problem with file detection when using helm-ls and yamlls, described in this issue

The only possible fix I've found is to install the vim-helm plugin via lazy and use this plugin definition: "ft = helm" (like this comment suggest)

Is there a way to achieve this in the context of nixvim ?

MattSturgeon commented 1 month ago

The only possible fix I've found is to install the vim-helm plugin via lazy and use this plugin definition: "ft = helm" (like this comment suggest)

Is there a way to achieve this in the context of nixvim ?

Does this section of the docs answer your question?

I'm half asking if our docs are any good and half asking if defining a vim filetype is the solution 😁

samos667 commented 1 month ago

The problem with the LSP-config is that it seems you cannot exclude an LSP server for a defined filetype. With the following declaration, opening a helm file (detection of the helm file type is based on the dir of the files, which must be on */template/*.yaml) with yaml file extension will trigger helmls and yamlls, but the expected behaviour, in this context, is to attach only helmls.

{
  plugins = {
    helm.enable = true;
    lsp.servers = {
      helm-ls = {
        filetypes = ["helm"];
        enable = true;
      };

      yamlls = {
        enable = true;
        filetypes = ["yaml"];
      };
    };
  };
}

image

Sadly I cannot find how to exclude a filetype for a specific LSP in LSP-config...

samos667 commented 1 week ago

It's really frustrating, is like the only way to have a proper support for helm is to use this "obscure" lazy option.

There is no way to have a similar behavior in Nixvim context ?

MattSturgeon commented 1 week ago

Does calling setup in a ftplugin file help?

samos667 commented 1 week ago

You mean like this ?

{
  extraFiles = {
    "ftplugin/lazy.lua".text = ''
      require("lazy").setup({
        -- towolf/vim-helm provides basic syntax highlighting and filetype detection
        -- ft = 'helm' is important to not start yamlls
        { 'towolf/vim-helm', ft = 'helm' },
      })
    '';
  };
  plugins = {
    # helm.enable = true;
    lazy.enable = true;
    lsp.servers = {
      helm-ls = {
        filetypes = ["helm"];
        enable = true;
      };

      yamlls = {
        enable = true;
        filetypes = ["yaml"];
      };
    };
  };
}

It doesn't seem to install the vim-helm plugin this way. And uncommenting causes the same issue as before.

MattSturgeon commented 1 week ago

(Re-opening as #997 was only ever marked as a "partial" fix)

You mean like this

I was thinking more like:

files."ftplugin/helm.lua" = {
  plugins.lsp = {
    enable = true;
    servers.helm-ls = {
      filetypes = ["helm"];
      enable = true;
    };
  };
}

But that seems too simple to actually work, there'd probably be issues with lsp being setup more than once...

samos667 commented 1 week ago

Damn, always to protect my eyes when writing/reading helm template, I disable diagnostics by stopping LSP. But this time I missclick and just restart LSP. And in this case I found the expected behavior on helm-ls ! image

Sadly is for this buffer only, when opening another template file I get yamlls attached too and have to restart LSP for this buffer. image

This is really weird, but I think I can deal with a autocmd to restart LSP when opening a yaml file

samos667 commented 1 week ago

Yeah a simply autocmd make the job !

{
  autoCmd = [
    {
      event = "FileType";
      pattern = "helm";
      command = "LspRestart";
    }
  ];
}