From bc71b13a88b8ebb46b631c04b5937e1963a5ce12 Mon Sep 17 00:00:00 2001 From: Mystical-C <64483945+MysticalDevil@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:46:26 +0800 Subject: [PATCH] fix: Adjust conform.nvim formatter configs --- lua/devil/format/conform.lua | 59 ++++++++++----------------------- lua/devil/plugins/languages.lua | 1 + 2 files changed, 19 insertions(+), 41 deletions(-) diff --git a/lua/devil/format/conform.lua b/lua/devil/format/conform.lua index 544104f..38f2cb2 100644 --- a/lua/devil/format/conform.lua +++ b/lua/devil/format/conform.lua @@ -8,13 +8,26 @@ local opts = { -- Map of filetype to formatters formatters_by_ft = { bash = { "beautysh" }, - go = { "gofumpt", "goimports", "golines" }, - lua = { "stylua" }, + c = { "clang_format" }, + clojure = { "zprint" }, + cmake = { "cmake_format" }, + cpp = { "clang_format" }, + cs = { "charpier" }, + dart = { "dart_format" }, + elixir = { "mix" }, + fish = { "fish_indent" }, + go = { "gofumpt", "goimports-reviser", "golines" }, + java = { "google-java-format" }, javascript = { { "prettierd", "prettier" } }, json = { "jq" }, + kotlin = { "ktlint" }, + lua = { "stylua" }, + perl = { "perlimports", "perltidy" }, python = { "isort", "black" }, + ruby = { "standardrb" }, rust = { "rustfmt" }, scala = { "scalafmt" }, + sh = { "beautysh" }, toml = { "taplo" }, xml = { "xmlformat" }, yaml = { "yamlfmt" }, @@ -45,50 +58,14 @@ local opts = { notify_on_error = true, -- Define custom formatters here formatters = { - my_formatter = { - -- This can be a string or a function that returns a string - command = "my_cmd", - -- OPTIONAL - all fields below this are optional - -- A list of strings, or a function that returns a list of strings - -- Return a single string instead to run the command in a shell - args = { "--stdin-from-filename", "$FILENAME" }, - -- If the formatter supports range formatting, create the range arguments here - range_args = function(ctx) - return { "--line-start", ctx.range.start[1], "--line-end", ctx.range["end"][1] } - end, - -- Send file contents to stdin, read new contents from stdout (default true) - -- When false, will create a temp file (will appear in "$FILENAME" args). The temp - -- file is assumed to be modified in-place by the format command. + prettier = { + command = require("conform.util").find_executable({ "node_modules/.bin/prettier" }, "prettier"), + args = { "--no-semi" }, stdin = true, - -- A function that calculates the directory to run the command in cwd = require("conform.util").root_file({ ".editorconfig", "package.json" }), - -- When cwd is not found, don't run the formatter (default false) require_cwd = true, - -- When returns false, the formatter will not be used - condition = function(ctx) - return vim.fs.basename(ctx.filename) ~= "README.md" - end, - -- Exit codes that indicate success (default {0}) - exit_codes = { 0, 1 }, - -- Environment variables. This can also be a function that returns a table. - env = { - VAR = "value", - }, }, - -- These can also be a function that returns the formatter - other_formatter = function() - return { - command = "my_cmd", - } - end, }, } conform.setup(opts) - -vim.api.nvim_create_autocmd("BufWritePre", { - pattern = "*", - callback = function(args) - require("conform").format({ bufnr = args.buf }) - end, -}) diff --git a/lua/devil/plugins/languages.lua b/lua/devil/plugins/languages.lua index baf1a83..d7a9d7b 100644 --- a/lua/devil/plugins/languages.lua +++ b/lua/devil/plugins/languages.lua @@ -38,6 +38,7 @@ return { "mfussenegger/nvim-dap", "mfussenegger/nvim-lint", "mhartington/formatter.nvim", + "stevearc/conform.nvim", "nvimtools/none-ls.nvim", }, },