diff options
author | Steven Arcangeli <506791+stevearc@users.noreply.github.com> | 2023-12-06 22:20:29 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-06 22:20:29 -0800 |
commit | 659838ff4244ef6af095395ce68aaaf99fa8e696 (patch) | |
tree | b92754f2de1a225187769ed2c30e01a3ea703b3c /scripts/generate.py | |
parent | 8d0421a11b2944c6c059e0936a95182972921c30 (diff) |
refactor!: formatter config functions take self as first argument (#233)
This is a breaking API change, but there is a shim in place that will keep existing functions working, just with a warning notification. Most people should not encounter this at all. For anyone overriding a formatter config value with a function that takes `(ctx)` as the parameter, it will need to be updated to take `(self, ctx)`.
Diffstat (limited to 'scripts/generate.py')
-rwxr-xr-x | scripts/generate.py | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/scripts/generate.py b/scripts/generate.py index f9db2a2..b4da7b4 100755 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -141,17 +141,41 @@ def gen_options_vimdoc() -> VimdocSection: return section -def gen_autocmd_vimdoc() -> VimdocSection: - section = VimdocSection("Autoformat", "conform-autoformat", ["\n"]) +def gen_self_compat_vimdoc() -> VimdocSection: + section = VimdocSection("self argument migration", "conform-self-args", ["\n"]) section.body.extend( wrap( - "If you want more complex logic than the `format_on_save` option allows, you can write it yourself using your own autocmd. For example:" + "The function arguments for formatter config functions have changed. Previously, they took a single `ctx` argument." + ) + ) + section.body.append( + """>lua + { + command = "phpcbf", + args = function(ctx) + return { "-q", "--stdin-path=" .. ctx.filename, "-" } + end + } +<""" + ) + section.body.extend( + wrap("Now, they take `self` as the first argument, and `ctx` as the second.") + ) + section.body.append( + """>lua + { + command = "phpcbf", + args = function(self, ctx) + return { "-q", "--stdin-path=" .. ctx.filename, "-" } + end + } +<""" + ) + section.body.extend( + wrap( + "The config values that can be defined as functions are: `command`, `args`, `range_args`, `cwd`, `env`, and `condition`." ) ) - section.body.append(">lua\n") - with open(AUTOFORMAT, "r", encoding="utf-8") as f: - section.body.extend(indent(f.readlines(), 4)) - section.body.append("<\n") return section @@ -171,7 +195,7 @@ def generate_vimdoc(): gen_options_vimdoc(), VimdocSection("API", "conform-api", render_vimdoc_api("conform", funcs)), gen_formatter_vimdoc(), - gen_autocmd_vimdoc(), + gen_self_compat_vimdoc(), ] ) |