diff --git a/examples/filetree.lua b/examples/filetree.lua index d3b3998..ed175b0 100644 --- a/examples/filetree.lua +++ b/examples/filetree.lua @@ -10,10 +10,10 @@ -- change on the underlying filesystem. -------------------------------------------------------------------------------- ---- @alias FsDir { kind: 'dir'; path: string; expanded: boolean; children: FsNode[] } ---- @alias FsFile { kind: 'file'; path: string } ---- @alias FsNode FsDir | FsFile ---- @alias ShowOpts { root_path?: string, width?: number, focus_path?: string } +--- @alias u.examples.FsDir { kind: 'dir'; path: string; expanded: boolean; children: u.examples.FsNode[] } +--- @alias u.examples.FsFile { kind: 'file'; path: string } +--- @alias u.examples.FsNode u.examples.FsDir | u.examples.FsFile +--- @alias u.examples.ShowOpts { root_path?: string, width?: number, focus_path?: string } local Buffer = require 'u.buffer' local Renderer = require('u.renderer').Renderer @@ -58,13 +58,13 @@ function H.relative(path, base) end --- @param root_path string ---- @return { tree: FsDir; path_to_node: table } +--- @return { tree: u.examples.FsDir; path_to_node: table } function H.get_tree_inf(root_path) logger:info { 'get_tree_inf', root_path } - --- @type table + --- @type table local path_to_node = {} - --- @type FsDir + --- @type u.examples.FsDir local tree = { kind = 'dir', path = H.normalize(root_path or '.'), @@ -77,8 +77,8 @@ function H.get_tree_inf(root_path) return { tree = tree, path_to_node = path_to_node } end ---- @param tree FsDir ---- @param path_to_node table +--- @param tree u.examples.FsDir +--- @param path_to_node table function H.populate_dir_children(tree, path_to_node) tree.children = {} @@ -135,7 +135,7 @@ local function _render_in_buffer(opts) local parts = H.split_path(H.relative(focused_path, tree_inf.tree.path)) local path_to_node = tree_inf.path_to_node - --- @param node FsDir + --- @param node u.examples.FsDir --- @param child_names string[] local function expand_to(node, child_names) if #child_names == 0 then return end @@ -310,7 +310,7 @@ local function _render_in_buffer(opts) -- local renderer = Renderer.new(opts.bufnr) tracker.create_effect(function() - --- @type { tree: FsDir; path_to_node: table } + --- @type { tree: u.examples.FsDir; path_to_node: table } local tree_inf = s_tree_inf:get() local tree = tree_inf.tree @@ -329,7 +329,7 @@ local function _render_in_buffer(opts) --- Since the filesystem is a recursive tree of nodes, we need to --- recursively render each node. This function does just that: - --- @param node FsNode + --- @param node u.examples.FsNode --- @param level number local function render_node(node, level) local name = vim.fs.basename(node.path) @@ -414,7 +414,7 @@ end local current_inf = nil --- Show the filetree: ---- @param opts? ShowOpts +--- @param opts? u.examples.ShowOpts function M.show(opts) if current_inf ~= nil then return current_inf.controller end opts = opts or {} @@ -456,7 +456,7 @@ function M.hide() end --- Toggle the filetree: ---- @param opts? ShowOpts +--- @param opts? u.examples.ShowOpts function M.toggle(opts) if current_inf == nil then M.show(opts) diff --git a/examples/notify.lua b/examples/notify.lua index 869404f..7d289d5 100644 --- a/examples/notify.lua +++ b/examples/notify.lua @@ -14,7 +14,7 @@ local ICONS = { } local DEFAULT_ICON = { text = '', group = 'DiagnosticSignOk' } ---- @alias Notification { +--- @alias u.examples.Notification { --- kind: number; --- id: number; --- text: string; @@ -30,7 +30,7 @@ local s_notifications = s_notifications_raw:debounce(50) -- Render effect: tracker.create_effect(function() - --- @type Notification[] + --- @type u.examples.Notification[] local notifs = s_notifications:get() if #notifs == 0 then @@ -99,14 +99,14 @@ local function my_notify(msg, level, opts) local id = math.random(math.huge) - --- @param notifs Notification[] + --- @param notifs u.examples.Notification[] s_notifications_raw:schedule_update(function(notifs) table.insert(notifs, { kind = level, id = id, text = msg }) return notifs end) vim.defer_fn(function() - --- @param notifs Notification[] + --- @param notifs u.examples.Notification[] s_notifications_raw:schedule_update(function(notifs) for i, notif in ipairs(notifs) do if notif.id == id then diff --git a/examples/picker.lua b/examples/picker.lua index a388733..866d8fc 100644 --- a/examples/picker.lua +++ b/examples/picker.lua @@ -44,7 +44,7 @@ local function shallow_copy_arr(arr) return vim.iter(arr):totable() end -- shortest portion of this function. -------------------------------------------------------------------------------- ---- @alias SelectController { +--- @alias u.examples.SelectController { --- get_items: fun(): T[]; --- set_items: fun(items: T[]); --- set_filter_text: fun(filter_text: string); @@ -53,17 +53,17 @@ local function shallow_copy_arr(arr) return vim.iter(arr):totable() end --- set_selected_indices: fun(indicies: number[], ephemeral?: boolean); --- close: fun(); --- } ---- @alias SelectOpts { +--- @alias u.examples.SelectOpts { --- items: `T`[]; --- multi?: boolean; ---- format_item?: fun(item: T): Tree; +--- format_item?: fun(item: T): u.renderer.Tree; --- on_finish?: fun(items: T[], indicies: number[]); --- on_selection_changed?: fun(items: T[], indicies: number[]); ---- mappings?: table; +--- mappings?: table; --- } --- @generic T ---- @param opts SelectOpts +--- @param opts u.examples.SelectOpts function M.create_picker(opts) -- {{{ local is_in_insert_mode = vim.api.nvim_get_mode().mode:sub(1, 1) == 'i' local stopinsert = not is_in_insert_mode @@ -557,7 +557,7 @@ function M.create_picker(opts) -- {{{ return safe_run(function() H.finish(true) end) end - return controller --[[@as SelectController]] + return controller --[[@as u.examples.SelectController]] end -- }}} -------------------------------------------------------------------------------- diff --git a/lua/u/renderer.lua b/lua/u/renderer.lua index d99c3a7..7af561f 100644 --- a/lua/u/renderer.lua +++ b/lua/u/renderer.lua @@ -373,6 +373,10 @@ function Renderer:_expr_map_callback(mode, lhs) -- {{{ end -- }}} function Renderer:_on_text_changed() + -- Reset changedtick, so that the reconciler knows to refresh its cached + -- buffer-content before computing the diff: + self.changedtick = 0 + --- @type integer, integer local l, c = unpack(vim.api.nvim_win_get_cursor(0)) l = l - 1 -- make it actually 0-based @@ -574,13 +578,13 @@ function TreeBuilder:tree() return self.nodes end -- Levenshtein utility {{{ -- luacheck: ignore ---- @alias LevenshteinChange ({ kind: 'add'; item: T; index: number; } | { kind: 'delete'; item: T; index: number; } | { kind: 'change'; from: T; to: T; index: number; }) +--- @alias u.renderer.LevenshteinChange ({ kind: 'add'; item: T; index: number; } | { kind: 'delete'; item: T; index: number; } | { kind: 'change'; from: T; to: T; index: number; }) --- @private --- @generic T --- @param x `T`[] --- @param y T[] --- @param cost? { of_delete?: fun(x: T): number; of_add?: fun(x: T): number; of_change?: fun(x: T, y: T): number; } ---- @return LevenshteinChange[] The changes, from last (greatest index) to first (smallest index). +--- @return u.renderer.LevenshteinChange[] The changes, from last (greatest index) to first (smallest index). function H.levenshtein(x, y, cost) -- At the moment, this whole `cost` plumbing is not used. Deletes have the -- same cost as Adds or Changes. I can imagine a future, however, where @@ -631,7 +635,7 @@ function H.levenshtein(x, y, cost) -- Backtrack to find the changes local i = m local j = n - --- @type LevenshteinChange[] + --- @type u.renderer.LevenshteinChange[] local changes = {} while i > 0 or j > 0 do @@ -648,7 +652,7 @@ function H.levenshtein(x, y, cost) if is_first_min(cost_of_change, cost_of_add, cost_of_delete) then -- potential change if x[i] ~= y[j] then - --- @type LevenshteinChange + --- @type u.renderer.LevenshteinChange local change = { kind = 'change', from = x[i], index = i, to = y[j] } table.insert(changes, change) end @@ -656,13 +660,13 @@ function H.levenshtein(x, y, cost) j = j - 1 elseif is_first_min(cost_of_add, cost_of_change, cost_of_delete) then -- addition - --- @type LevenshteinChange + --- @type u.renderer.LevenshteinChange local change = { kind = 'add', item = y[j], index = i + 1 } table.insert(changes, change) j = j - 1 elseif is_first_min(cost_of_delete, cost_of_change, cost_of_add) then -- deletion - --- @type LevenshteinChange + --- @type u.renderer.LevenshteinChange local change = { kind = 'delete', item = x[i], index = i } table.insert(changes, change) i = i - 1