Custom column API #36
Labels
No labels
autorelease: pending
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
upstream/digest
upstream/pr
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
barrettruth/canola.nvim#36
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Users want to register custom columns (recursive directory sizes, git blame info, custom metadata fields). The internal
columns.register(name, def)function exists but is completely undocumented. There is no public API, no vimdoc entry, no recipe, and no stability guarantee. Third-party plugins (e.g. canola-git for a git status column) have no reliable surface to hook into.Consolidates
Current state
lua/oil/columns.luaexposes:Adapters call this at module load time for their own columns (icon, type, name in
columns.lua; size, permissions, mtime, owner, group inadapters/files.lua). The interface works but is internal-only.Proposed public API
This is a thin re-export of
columns.registerthrough the publicoilmodule, making it part of the stable API surface.Column definition interface
Every field except
renderis optional.render(entry, conf, bufnr) -> oil.TextChunk(required)Returns the text and highlight for one cell.
entryis a 4-tuple{id, name, type, meta}.confis the per-column config table from the user'scolumnslist (e.g.{ "mtime", format = "%Y-%m-%d" }). Return value is either a plain string, a{text, hl_group}pair, orcolumns.EMPTY({"-", "OilEmpty"}) when the column has no value for this entry.parse(line, conf) -> value, remainderConsumes the column's text from the front of
lineand returns the parsed value plus the unconsumed remainder. Required for physical columns (those that appear in the buffer). Omit for virtual columns (virtual = true).compare(entry, parsed_value) -> booleanReturns true when the parsed value differs from the cached entry's current value. Used to generate
DiffChangeactions on:w. Only needed for columns that represent mutable file metadata (e.g. permissions, ownership).render_action(action) -> stringReturns a human-readable description of the change action for the confirmation prompt.
perform_action(action, callback)Executes the change (e.g.
fs_chmod).callbackisfun(err: string|nil).get_sort_value(entry) -> number|stringReturns a sortable scalar for this entry. Used when the user sorts by this column.
create_sort_value_factory(num_entries) -> fun(entry) -> number|stringAlternative to
get_sort_valuefor sort implementations that need to precompute state across all entries (e.g. natural-order sorting with memoization). Takes precedence overget_sort_valuewhen present.virtual(boolean, v1.1+)When
true, the column renders asvirt_textvia extmarks rather than inline buffer text.parseis not called for virtual columns. See #142.Adapter-scoped columns
Columns registered via
require('canola').register_columnare global — they appear for all adapters. Adapter-specific columns (size, permissions, mtime) are registered through the adapter'sget_column(name)method, which takes precedence for that adapter's scheme.If a third-party column should only appear for local files, the
renderfunction can checkentry[FIELD_META].statand returncolumns.EMPTYwhen stat is absent (as the built-in size column does).Work needed
register_columnfromlua/oil/init.luaoil.register_columnentry todoc/canola.txtwith the full field reference aboveoil-recipe-custom-columnrecipe to vimdoc showing a working example (e.g. a column that renders the number of hardlinks fromentry[FIELD_META].stat.nlink)virtualfield tooil.ColumnDefinitiontype annotation incolumns.lua(coordinate with #142)Implemented in #229 —
register_column()exported fromlua/canola/init.lua, vimdoc and recipe added.