BREAKING CHANGE: Delta Pager + Large Refactor (#43)
BREAKING CHANGE: This MR addresses an underlying issue with the original implementation in regards to detecting line numbers for comments. As such, this is a major breaking change. The setup function signature has changed, please review the `README.md` for the new arguments. The delta pager has also been added as a dependency: https://github.com/dandavison/delta There will be future work to implement a native solution for parsing changes and line numbers.
This commit is contained in:
committed by
GitHub
parent
ed67a03f8f
commit
19468a3d2d
67
lua/gitlab/async.lua
Normal file
67
lua/gitlab/async.lua
Normal file
@@ -0,0 +1,67 @@
|
||||
-- This module is responsible for calling APIs in sequence. It provides
|
||||
-- an abstraction around the APIs that lets us ensure state.
|
||||
local server = require("gitlab.server")
|
||||
local job = require("gitlab.job")
|
||||
local state = require("gitlab.state")
|
||||
|
||||
local M = {}
|
||||
|
||||
Async = {
|
||||
cb = nil
|
||||
}
|
||||
|
||||
function Async:new(o)
|
||||
o = o or {}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
|
||||
function Async:init(cb)
|
||||
self.cb = cb
|
||||
end
|
||||
|
||||
function Async:fetch(dependencies, i)
|
||||
if i > #dependencies then
|
||||
self:cb()
|
||||
return
|
||||
end
|
||||
|
||||
local dependency = dependencies[i]
|
||||
|
||||
-- Do not call endpoint unless refresh is required
|
||||
if state[dependency.state] ~= nil and not dependency.refresh then
|
||||
self:fetch(dependencies, i + 1)
|
||||
return
|
||||
end
|
||||
|
||||
job.run_job(dependency.endpoint, "GET", dependency.body, function(data)
|
||||
state[dependency.state] = data[dependency.key]
|
||||
self:fetch(dependencies, i + 1)
|
||||
end)
|
||||
end
|
||||
|
||||
-- Will call APIs in sequence and set global state
|
||||
M.sequence = function(dependencies, cb)
|
||||
return function()
|
||||
local handler = Async:new()
|
||||
handler:init(cb)
|
||||
|
||||
if not state.is_gitlab_project then
|
||||
vim.notify("The gitlab.nvim state was not set. Do you have a .gitlab.nvim file configured?", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
if state.go_server_running then
|
||||
handler:fetch(dependencies, 1)
|
||||
return
|
||||
end
|
||||
|
||||
server.start_server(function()
|
||||
state.go_server_running = true
|
||||
handler:fetch(dependencies, 1)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user