Drop setup() entirely #39

Closed
opened 2026-09-21 18:54:23 +00:00 by barrettruth · 0 comments
Owner

Original issue: barrettruth/canola.nvim#199
Original author: barrettruth
Original date: 2026-03-19T17:19:08Z

Overview

Remove M.setup() from lua/canola/init.lua and replace it with initialization driven by plugin/canola.lua reading vim.g.canola. This is a hard break — no compatibility shim, no fallback path.

Motivation

setup() is a call-time initialization pattern inherited from the Lua plugin ecosystem. It requires the user to require() the plugin explicitly, which conflicts with lazy-loading and makes session restore fragile (the plugin may not be initialized when a session buffer tries to load). vim.g.canola is set before any plugin loads, so plugin/canola.lua can always read a fully-formed config at startup regardless of when or whether the user require()s anything.

Keeping setup() alongside vim.g.canola creates two config surfaces that must be merged in a defined order, with edge cases around partial configs and late calls. Dropping setup() entirely eliminates that complexity.

What changes

lua/canola/init.lua:

  • Remove M.setup() and its body
  • Remove the call-time guard (if M._initialized then return end) that setup() currently uses

plugin/canola.lua:

  • Read vim.g.canola (defaulting to {} if unset)
  • Call the internal initializer directly (bypassing the removed setup())
  • This file is the single initialization entry point

lua/canola/config.lua:

  • Internal config.setup(opts) remains — it merges opts with defaults and sets module fields. The public M.setup() wrapper in init.lua is what's removed.

Setter API

Function-valued config fields cannot live in vim.g. They are replaced by setter functions on the public API:

  • require('canola').set_is_hidden_file(fn)
  • require('canola').set_is_always_hidden(fn)
  • require('canola').set_highlight_filename(fn)
  • require('canola').set_disable_preview(fn)

These must be called after the plugin loads (e.g. in an after/plugin file or lazy.nvim's config callback). They update the live config and take effect on the next render.

Hook replacements

git.add, git.mv, git.rm, float.override, and float.get_win_title are replaced by User autocmds. See #182 for the full autocmd event design.

Migration guide outline

Users coming from oil.nvim or canola v1.0:

  1. Remove require('oil').setup({...}) / require('canola').setup({...}) from your config.
  2. Move all serializable options to vim.g.canola = {...} in your init.lua or equivalent, before any plugin loads.
  3. Move function-valued options to setter calls (after plugin load):
    • view_options.is_hidden_file → require('canola').set_is_hidden_file(fn)
    • view_options.is_always_hidden → require('canola').set_is_always_hidden(fn)
    • view_options.highlight_filename → require('canola').set_highlight_filename(fn)
    • preview_win.disable_preview → require('canola').set_disable_preview(fn)
  4. Move hook functions (git.add, etc.) to the corresponding User autocmds (see #182).
  5. For lazy.nvim: use the init key (not opts) to set vim.g.canola.
  • #82 — vim.g.canola config system (full field reference)
  • #182 — User autocmd events (hook replacements)
  • #1 — original migration tracking issue
> Original issue: barrettruth/canola.nvim#199 > Original author: `barrettruth` > Original date: 2026-03-19T17:19:08Z ## Overview Remove `M.setup()` from `lua/canola/init.lua` and replace it with initialization driven by `plugin/canola.lua` reading `vim.g.canola`. This is a hard break — no compatibility shim, no fallback path. ## Motivation `setup()` is a call-time initialization pattern inherited from the Lua plugin ecosystem. It requires the user to `require()` the plugin explicitly, which conflicts with lazy-loading and makes session restore fragile (the plugin may not be initialized when a session buffer tries to load). `vim.g.canola` is set before any plugin loads, so `plugin/canola.lua` can always read a fully-formed config at startup regardless of when or whether the user `require()`s anything. Keeping `setup()` alongside `vim.g.canola` creates two config surfaces that must be merged in a defined order, with edge cases around partial configs and late calls. Dropping `setup()` entirely eliminates that complexity. ## What changes `lua/canola/init.lua`: - Remove `M.setup()` and its body - Remove the call-time guard (`if M._initialized then return end`) that `setup()` currently uses `plugin/canola.lua`: - Read `vim.g.canola` (defaulting to `{}` if unset) - Call the internal initializer directly (bypassing the removed `setup()`) - This file is the single initialization entry point `lua/canola/config.lua`: - Internal `config.setup(opts)` remains — it merges opts with defaults and sets module fields. The public `M.setup()` wrapper in `init.lua` is what's removed. ## Setter API Function-valued config fields cannot live in `vim.g`. They are replaced by setter functions on the public API: - `require('canola').set_is_hidden_file(fn)` - `require('canola').set_is_always_hidden(fn)` - `require('canola').set_highlight_filename(fn)` - `require('canola').set_disable_preview(fn)` These must be called after the plugin loads (e.g. in an `after/plugin` file or lazy.nvim's `config` callback). They update the live config and take effect on the next render. ## Hook replacements `git.add`, `git.mv`, `git.rm`, `float.override`, and `float.get_win_title` are replaced by User autocmds. See #182 for the full autocmd event design. ## Migration guide outline Users coming from oil.nvim or canola v1.0: 1. Remove `require('oil').setup({...})` / `require('canola').setup({...})` from your config. 2. Move all serializable options to `vim.g.canola = {...}` in your `init.lua` or equivalent, before any plugin loads. 3. Move function-valued options to setter calls (after plugin load): - `view_options.is_hidden_file` → `require('canola').set_is_hidden_file(fn)` - `view_options.is_always_hidden` → `require('canola').set_is_always_hidden(fn)` - `view_options.highlight_filename` → `require('canola').set_highlight_filename(fn)` - `preview_win.disable_preview` → `require('canola').set_disable_preview(fn)` 4. Move hook functions (`git.add`, etc.) to the corresponding User autocmds (see #182). 5. For lazy.nvim: use the `init` key (not `opts`) to set `vim.g.canola`. ## Related - #82 — `vim.g.canola` config system (full field reference) - #182 — User autocmd events (hook replacements) - #1 — original migration tracking issue
barrettruth added this to the v1.1 milestone 2026-09-21 18:54:23 +00:00
Sign in to join this conversation.
No description provided.