Advertisement
ziriuz84

Untitled

Nov 20th, 2024
68
0
5 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.25 KB | None | 0 0
  1.   { -- Autoformat
  2.     'stevearc/conform.nvim',
  3.     event = { 'BufWritePre' },
  4.     cmd = { 'ConformInfo' },
  5.     keys = {
  6.       {
  7.         '<leader>f',
  8.         function()
  9.           require('conform').format { async = true, lsp_format = 'fallback' }
  10.         end,
  11.         mode = '',
  12.         desc = '[F]ormat buffer',
  13.       },
  14.     },
  15.     opts = {
  16.       notify_on_error = false,
  17.       format_on_save = function(bufnr)
  18.         -- Check if file is in the specified directory
  19.         local file_path = vim.fn.expand '%:p'
  20.         local excluded_path = '/percorso/dove/non/formattare'
  21.         if string.find(file_path, excluded_path) then
  22.           return false
  23.         end
  24.  
  25.         -- Disable "format_on_save lsp_fallback" for languages that don't
  26.         -- have a well standardized coding style. You can add additional
  27.         -- languages here or re-enable it for the disabled ones.
  28.         local disable_filetypes = { c = true, cpp = true }
  29.         local lsp_format_opt
  30.         if disable_filetypes[vim.bo[bufnr].filetype] then
  31.           lsp_format_opt = 'never'
  32.         else
  33.           lsp_format_opt = 'fallback'
  34.         end
  35.         return {
  36.           timeout_ms = 500,
  37.           lsp_format = lsp_format_opt,
  38.         }
  39.       end,
  40.       formatters_by_ft = {
  41.         lua = { 'stylua' },
  42.         rust = { 'rust_analyzer' },
  43.         python = { 'black', 'isort' },
  44.         javascript = { 'prettierd' },
  45.         typescript = { 'prettierd' },
  46.         html = { 'prettierd' },
  47.         css = { 'prettierd' },
  48.         scss = { 'prettierd' },
  49.         json = { 'prettierd' },
  50.         yaml = { 'prettierd' },
  51.         markdown = { 'prettierd' },
  52.         graphql = { 'prettierd' },
  53.         php = { 'php-cs-fixer', 'pint' },
  54.         phtml = { 'php-cs-fixer', 'pint' },
  55.         -- Conform can also run multiple formatters in parallel
  56.         -- Conform can also run multiple formatters sequentially
  57.         -- python = { "isort", "black" },
  58.         --
  59.         -- You can use 'stop_after_first' to run the first available formatter from the list
  60.         -- javascript = { "prettierd", "prettier", stop_after_first = true },
  61.       },
  62.       formatters = {
  63.         php_cs_fixer = {
  64.           prepend_args = { '--rules=PSR12' },
  65.         },
  66.       },
  67.     },
  68.   },
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement