CppCXY / EmmyLuaCodeStyle

fast, powerful, and feature-rich Lua formatting and checking tool.
MIT License
139 stars 27 forks source link

`align_continuous_assign_statement=true` should exclude multi-line statements #137

Closed ddickstein closed 1 year ago

ddickstein commented 1 year ago

I have a Lua file (part of an nvim-cmp config) with a snippet that looks like this:

local mapping      = {
  ["<C-n>"] = {
    i = complete_and_select_next,
    c = function()
      if not expand_special_cmd_items() then
        complete_and_select_next()
      end
    end,
  },
  ["<C-p>"] = {
    i = complete_and_select_prev,
    c = function()
      if not expand_special_cmd_items() then
        complete_and_select_prev()
      end
    end,
  },
  ["<C-y>"] = {
    i = require "cmp.config.mapping".confirm({ select = false }),
    c = require "cmp.config.mapping".confirm({ select = false }),
  },
  ["<C-e>"] = {
    i = require "cmp.config.mapping".abort(),
    c = require "cmp.config.mapping".abort(),
  },
  ["<C-z>"] = {
    -- Normally <C-z> in command mode triggers wildmenu, so this is analogous.
    c = complete_and_select_next,
  },
  -- We don't enable up/down for command line b/c they are used to navigate history.
  ["<Up>"] = {
    i = select_prev_or_fall_back,
  },
  ["<Down>"] = {
    i = select_next_or_fall_back,
  },
  ["<Enter>"] = {
    i = function(fallback)
      cmp.close()
      fallback()
    end,
  },
}
mapping["<Tab>"]   = mapping["<C-n>"]
mapping["<S-Tab>"] = mapping["<C-p>"]

These are technically continuous assign statements, but the first one is so large that aligning it with the latter two doesn't really make sense. I think in general the readability benefit of aligning the assignments probably only applies to sequences of single-line assignments.

CppCXY commented 1 year ago

you can keep a sufficient distance between the bottom and top.

local t = 123

d   = 123
ddd = 123

If you feel that this distance is too long, you can adjust it align_continuous_line_space = 1