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.
Answer provided by @Alan Birtles in the comments is correct. The file name should be .clang-format
with a -
instead of .clangformat