aboutsummaryrefslogtreecommitdiffstats
path: root/lua/conform/formatters/clang-format.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/conform/formatters/clang-format.lua')
-rw-r--r--lua/conform/formatters/clang-format.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/lua/conform/formatters/clang-format.lua b/lua/conform/formatters/clang-format.lua
new file mode 100644
index 0000000..2e68fc1
--- /dev/null
+++ b/lua/conform/formatters/clang-format.lua
@@ -0,0 +1,22 @@
+local util = require("conform.util")
+---@type conform.FileFormatterConfig
+return {
+ meta = {
+ url = "https://www.kernel.org/doc/html/latest/process/clang-format.html",
+ description = "Tool to format C/C++/… code according to a set of rules and heuristics.",
+ },
+ command = "clang-format",
+ args = { "-assume-filename", "$FILENAME" },
+ range_args = function(self, ctx)
+ local start_offset, end_offset = util.get_offsets_from_range(ctx.buf, ctx.range)
+ local length = end_offset - start_offset
+ return {
+ "-assume-filename",
+ "$FILENAME",
+ "--offset",
+ tostring(start_offset),
+ "--length",
+ tostring(length),
+ }
+ end,
+}