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

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

Open
nogweii opened this issue Feb 27, 2024 · 1 comment
Open

Comments

@nogweii
Copy link

nogweii commented Feb 27, 2024

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
Copy link
Author

nogweii commented Feb 27, 2024

Ah, there's been conversation in the vim-helm issue tracker: towolf/vim-helm#15

And there already is some code in the plugin to specifically deal with helm files:

if vim.bo[bufnr].buftype ~= "" or vim.bo[bufnr].filetype == "helm" then

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?

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

No branches or pull requests

1 participant