Julian / lean.nvim

Neovim support for the Lean theorem prover
MIT License
276 stars 26 forks source link

Fix idempotency issue #277

Closed 4e554c4c closed 2 years ago

4e554c4c commented 2 years ago

It turns out that most of these come from the _DEFAULTS pattern. This is because of the following: original state:

tbl = { _DEFAULTS = ... }

after configuration with empty table, tbl = vim.tbl_extend(tbl._DEFAULTS, {}) which practically replaces tbl by tbl._DEFAULTS:

tbl = { ... }

after this, the next call to vim.tbl_extend(tbl._DEFAULTS, {}) fails, as tbl._DEFAULTS is nil.

The solution to this is to just call vim.tbl_extend(tbl, ...) and store the defaults in tbl itself. The ._DEFAULTS field can be preserved by copying to it after initialization.

Also command has been replaced with command! in vimscript and autocmds have been wrapped in an augroup which resets its state each call. This is also common practice that avoids duplicate autocommands.

Fixes https://github.com/Julian/lean.nvim/issues/145

Julian commented 2 years ago

Thanks. This looks pretty reasonable. I'm not really happy with the way we have config now in some other ways which is #39 but this definitely looks like an improvement! Let me know when/if it's ready to review.

4e554c4c commented 2 years ago

should be good to review now, thanks :)

Julian commented 2 years ago

Looks great! Really appreciated.