Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix idempotency issue #277

Merged
merged 2 commits into from
Sep 7, 2022
Merged

Fix idempotency issue #277

merged 2 commits into from
Sep 7, 2022

Conversation

4e554c4c
Copy link
Contributor

@4e554c4c 4e554c4c commented Sep 6, 2022

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 #145

@Julian
Copy link
Owner

Julian commented Sep 6, 2022

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.

It turns out that most of these come from the `_DEFAULTS` pattern. This
is because of the following:
original state:
```lua
tbl = { _DEFAULTS = ... }
```
after configuration with empty table, `tbl = vim.tbl_extend(tbl._DEFAULTS, {})`
which practically replaces `tbl` by `tbl._DEFAULTS`:
```lua
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
`autocmd`s have been wrapped in an `augroup` which resets its state each
call. This is also common practice that avoids duplicate autocommands.

Fixes Julian#145
@4e554c4c 4e554c4c marked this pull request as ready for review September 7, 2022 00:39
test plan:
```
$ TEST_FILE=lua/tests/setup_spec.lua ./lua/tests/scripts/run_tests.sh
========================================
Testing: 	lua/tests/setup_spec.lua
Success	||	lean.setup Does not crash when loaded twice

Success: 	1
Failed : 	0
Errors : 	0
========================================
```
@4e554c4c
Copy link
Contributor Author

4e554c4c commented Sep 7, 2022

should be good to review now, thanks :)

@Julian
Copy link
Owner

Julian commented Sep 7, 2022

Looks great! Really appreciated.

@Julian Julian merged commit 6e21689 into Julian:main Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make calling require'lean'.setup{} idempotent
2 participants