From 8257b071c80f97b6ae2822789f9050bbcd19c2c7 Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Mon, 6 May 2024 09:12:07 -0500 Subject: [PATCH] Bump minimum orgmode version, which introduces fix to promise:wait(); remove patch to promise:wait() --- DOCS.org | 6 +- README.org | 6 +- lua/org-roam/core/utils/promise.lua | 56 ------------------- .../core/utils/promise/packed_value.lua | 36 ------------ lua/org-roam/setup/plugin.lua | 8 --- 5 files changed, 6 insertions(+), 106 deletions(-) delete mode 100644 lua/org-roam/core/utils/promise.lua delete mode 100644 lua/org-roam/core/utils/promise/packed_value.lua diff --git a/DOCS.org b/DOCS.org index 6f63fa8..4fd5b71 100644 --- a/DOCS.org +++ b/DOCS.org @@ -6,7 +6,7 @@ ** Installation - This plugin depends on [[https://github.com/nvim-orgmode/orgmode][nvim-orgmode/orgmode]] @ [[https://github.com/nvim-orgmode/orgmode/commit/d4cc3210f235a845de8d372d02482163d31ded93][commit d4cc321]]. + This plugin depends on [[https://github.com/nvim-orgmode/orgmode][nvim-orgmode/orgmode]] @ [[https://github.com/nvim-orgmode/orgmode/commit/03a207898671c3070ed5eccbe3528bc48ee8d09e][commit 03a2078]]. *** lazy.nvim @@ -16,7 +16,7 @@ dependencies = { { "nvim-orgmode/orgmode", - commit = "d4cc3210f235a845de8d372d02482163d31ded93", + commit = "03a207898671c3070ed5eccbe3528bc48ee8d09e", }, }, config = function() @@ -35,7 +35,7 @@ requires = { { "nvim-orgmode/orgmode", - commit = "d4cc3210f235a845de8d372d02482163d31ded93", + commit = "03a207898671c3070ed5eccbe3528bc48ee8d09e", }, }, config = function() diff --git a/README.org b/README.org index fd794dd..5fab22a 100644 --- a/README.org +++ b/README.org @@ -9,7 +9,7 @@ ** Installation - This plugin depends on [[https://github.com/nvim-orgmode/orgmode][nvim-orgmode/orgmode]] @ [[https://github.com/nvim-orgmode/orgmode/commit/d4cc3210f235a845de8d372d02482163d31ded93][commit d4cc321]]. + This plugin depends on [[https://github.com/nvim-orgmode/orgmode][nvim-orgmode/orgmode]] @ [[https://github.com/nvim-orgmode/orgmode/commit/03a207898671c3070ed5eccbe3528bc48ee8d09e][commit 03a2078]]. *** lazy.nvim (recommended) @@ -22,7 +22,7 @@ dependencies = { { "nvim-orgmode/orgmode", - commit = "d4cc3210f235a845de8d372d02482163d31ded93", + commit = "03a207898671c3070ed5eccbe3528bc48ee8d09e", }, }, config = function() @@ -46,7 +46,7 @@ requires = { { "nvim-orgmode/orgmode", - commit = "d4cc3210f235a845de8d372d02482163d31ded93", + commit = "03a207898671c3070ed5eccbe3528bc48ee8d09e", }, }, config = function() diff --git a/lua/org-roam/core/utils/promise.lua b/lua/org-roam/core/utils/promise.lua deleted file mode 100644 index 5a9a785..0000000 --- a/lua/org-roam/core/utils/promise.lua +++ /dev/null @@ -1,56 +0,0 @@ -------------------------------------------------------------------------------- --- PROMISE.LUA --- --- Utilities to operate on promises. -------------------------------------------------------------------------------- - -local PackedValue = require("org-roam.core.utils.promise.packed_value") - -local M = {} - ----Waits for a promise to complete, throwing an error on timeout. ---- ----This serves as a copy of the function from `orgmode.utils.promise`, except ----that it throws an error when the timeout is exceeded instead of returning nil. ----@generic T ----@param promise OrgPromise ----@param timeout? number ----@return T -function M.wait(promise, timeout) - local is_done = false - local has_error = false - local result = nil - - promise:next(function(...) - result = PackedValue:new(...) - is_done = true - return ... - end):catch(function(...) - has_error = true - result = PackedValue:new(...) - is_done = true - end) - - timeout = timeout or 5000 - local success, code = vim.wait(timeout, function() - return is_done - end, 1) - - local value = result and result:unpack() - - if has_error then - return error(value) - end - - if not success and code == -1 then - return error("promise timeout of " .. tostring(timeout) .. "ms reached") - elseif not success and code == -2 then - return error("promise interrupted") - elseif not success then - return error("promise failed with unknown reason") - end - - return value -end - -return M diff --git a/lua/org-roam/core/utils/promise/packed_value.lua b/lua/org-roam/core/utils/promise/packed_value.lua deleted file mode 100644 index e653925..0000000 --- a/lua/org-roam/core/utils/promise/packed_value.lua +++ /dev/null @@ -1,36 +0,0 @@ -------------------------------------------------------------------------------- --- PACKED_VALUE.LUA --- --- Utility for packing values. -------------------------------------------------------------------------------- - -local vim = vim - ----@class org-roam.core.utils.promise.PackedValue ----@field private __values table -local M = {} -M.__index = M - -function M:new(...) - local values = vim.F.pack_len(...) - local tbl = { __values = values } - return setmetatable(tbl, M) -end - -function M:pcall(f) - local ok_and_value = function(ok, ...) - return ok, M.new(...) - end - return ok_and_value(pcall(f, self:unpack())) -end - -function M:unpack() - return vim.F.unpack_len(self.__values) -end - -function M:first() - local first = self:unpack() - return first -end - -return M diff --git a/lua/org-roam/setup/plugin.lua b/lua/org-roam/setup/plugin.lua index e6cb8d9..61e22ef 100644 --- a/lua/org-roam/setup/plugin.lua +++ b/lua/org-roam/setup/plugin.lua @@ -46,12 +46,4 @@ return function(roam) -- Fall back to the default implementation return require("orgmode.org.mappings").open_at_point(self) end - - -- Overwrite promise.wait to throw an error when wait fails instead of returning nil - -- - -- TODO: This exists as the current wait implementation does not fail on timeout and - -- instead returns nil. If this is resolved, we will remove this override. - -- - -- See https://github.com/nvim-orgmode/orgmode/pull/723 - require("orgmode.utils.promise").wait = require("org-roam.core.utils.promise").wait end