4

I am using none-ls to configure Clang-Format, version 19.1.0, as an LSP in Neovim, version v0.10.2. I want to use a .clangformat file to change the formatting rules, but I cannot figure out how to make Neovim use these new rules.

Right now the .clangformat file is is my user directory, which is a parent directory of my project, but when I run vim.lsp.buf.format, the rules are not applied. When run the executable from the terminal passing in the path to the .clangformat file using :!clang-format -i fileToBeFormatted --style=file: .clangformatPath it correctly applies the rules.

Is this an issue with how none-ls is configured or where the file is located.

My configuration for none-ls using Lazy:

return {
    "nvimtools/none-ls.nvim",
    config = function()
        local null_ls = require("null-ls")
        null_ls.setup({
            debug = true,
            sources = {
                null_ls.builtins.formatting.stylua,
                null_ls.builtins.diagnostics.clang_tidy,
                null_ls.builtins.formatting.clang_format.with({
            extra_args = { "--style=file" },
        }),
            },
        })
        vim.keymap.set("n", "<leader>fo", vim.lsp.buf.format, {})
    end,
}

Just want to add that I would like the keybind <leader>fo to remain language neutral, so I would appreciate if a solution other than hardcoding the .clangformat file location could be found.

3
  • 3
    The filename should be .clang-format Commented Oct 25, 2024 at 6:42
  • clangd is the LSP provider. This is also why I got off neovim and use helix as my CLI editor of choice. That's way too much code to just say you want a formatter. Commented Oct 25, 2024 at 15:18
  • none-ls configures clang-format to act as a LSP, so you can use vim.lsp.buf.format to format your code. I use mason and lspconfig to setup clangd, but this is unrelated to clangd Commented Oct 25, 2024 at 16:23

1 Answer 1

3

Answer provided by @Alan Birtles in the comments is correct. The file name should be .clang-format with a - instead of .clangformat

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.