someone-stole-my-name / yaml-companion.nvim

Get, set and autodetect YAML schemas in your buffers.
MIT License
202 stars 18 forks source link

Any thoughts on how to disable yamlls for specific file types/patterns? #43

Open nogweii opened 4 months ago

nogweii commented 4 months ago

I'm thinking about YAML files that are templated, usually with a {{ }} based syntax, causing all sorts of errors and complaints about the file. Helm, Jinja, Go templates all are problems.

I've tried adding a custom root_dir function to my settings that returns nil when a file matches a pattern but then neovim falls back to running the LSP in single-file mode.

It would be very cool if you knew how to configure yamlls to not run for specific file patterns and types (since it's not going to be able to handle these files very well).

nogweii commented 4 months ago

Ah, there's been conversation in the vim-helm issue tracker: https://github.com/towolf/vim-helm/issues/15

And there already is some code in the plugin to specifically deal with helm files: https://github.com/someone-stole-my-name/yaml-companion.nvim/blob/4de1e1546abc461f62dee02fcac6a02debd6eb9e/lua/yaml-companion/context/init.lua#L108

I'm looking for something a little more generic, but both of those inspired me to write this function:

  on_attach = function(client, bufnr)
    local filename = vim.api.nvim_buf_get_name(bufnr)
    if filename:match('charts/.+/templates/.+%.ya?ml$') then
      vim.defer_fn(function()
        vim.lsp.buf_detach_client(bufnr, client.id)
      end, 100)
    end
  end

I had to put it in a defer as the client wasn't attached attached just yet when the function ran. I wonder why other's examples don't need to do the same?