Fix Notify Requires (#2)

Moves all notify require calls outside of scheduled calls
This commit is contained in:
Harrison (Harry) Cramer
2023-04-22 12:52:07 -04:00
committed by GitHub
parent 6ec3f15966
commit 6154d4c9f3
4 changed files with 16 additions and 12 deletions

View File

@@ -1,5 +1,6 @@
local Menu = require("nui.menu") local Menu = require("nui.menu")
local NuiTree = require("nui.tree") local NuiTree = require("nui.tree")
local notify = require("notify")
local Job = require("plenary.job") local Job = require("plenary.job")
local state = require("gitlab.state") local state = require("gitlab.state")
local u = require("gitlab.utils") local u = require("gitlab.utils")
@@ -93,7 +94,7 @@ M.delete_comment = function()
on_stdout = function(_, line) on_stdout = function(_, line)
vim.schedule(function() vim.schedule(function()
if line ~= nil and line ~= "" then if line ~= nil and line ~= "" then
require("notify")(line, "info") notify(line, "info")
state.tree:remove_node("-" .. note_id) state.tree:remove_node("-" .. note_id)
local discussion_node = state.tree:get_node("-" .. discussion_id) local discussion_node = state.tree:get_node("-" .. discussion_id)
if not discussion_node:has_children() then if not discussion_node:has_children() then
@@ -155,7 +156,7 @@ M.send_edits = function(text)
on_stdout = function(_, line) on_stdout = function(_, line)
local note = vim.json.decode(line) local note = vim.json.decode(line)
if note == nil then if note == nil then
require("notify")("There was an issue editing the note", "error") notify("There was an issue editing the note", "error")
return return
end end
@@ -177,7 +178,7 @@ M.send_edits = function(text)
state.tree:render() state.tree:render()
local buf = vim.api.nvim_get_current_buf() local buf = vim.api.nvim_get_current_buf()
u.darken_metadata(buf, '') u.darken_metadata(buf, '')
require("notify")("Edited comment!") notify("Edited comment!")
end) end)
end, end,
on_stderr = u.print_error on_stderr = u.print_error

View File

@@ -1,5 +1,6 @@
local u = require("gitlab.utils") local u = require("gitlab.utils")
local NuiTree = require("nui.tree") local NuiTree = require("nui.tree")
local notify = require("notify")
local state = require("gitlab.state") local state = require("gitlab.state")
local Job = require("plenary.job") local Job = require("plenary.job")
local Popup = require("nui.popup") local Popup = require("nui.popup")
@@ -27,7 +28,7 @@ M.send_reply = function(text)
on_stdout = function(_, line) on_stdout = function(_, line)
local note = vim.json.decode(line) local note = vim.json.decode(line)
if note == nil then if note == nil then
require("notify")("There was an issue creating the note", "error") notify("There was an issue creating the note", "error")
return return
end end
@@ -39,7 +40,7 @@ M.send_reply = function(text)
state.tree:render() state.tree:render()
local buf = vim.api.nvim_get_current_buf() local buf = vim.api.nvim_get_current_buf()
u.darken_metadata(buf, '') u.darken_metadata(buf, '')
require("notify")("Sent reply!") notify("Sent reply!")
end) end)
end, end,
on_stderr = u.print_error on_stderr = u.print_error
@@ -62,7 +63,7 @@ M.list_discussions = function()
vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown') vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown')
vim.api.nvim_set_current_buf(buf) vim.api.nvim_set_current_buf(buf)
if discussions == nil then if discussions == nil then
require("notify")("No discussions found for this MR", "warn") notify("No discussions found for this MR", "warn")
else else
local allDiscussions = {} local allDiscussions = {}
for i, discussion in ipairs(discussions) do for i, discussion in ipairs(discussions) do

View File

@@ -1,5 +1,6 @@
local Job = require("plenary.job") local Job = require("plenary.job")
local state = require("gitlab.state") local state = require("gitlab.state")
local notify = require("notify")
local discussions = require("gitlab.discussions") local discussions = require("gitlab.discussions")
local summary = require("gitlab.summary") local summary = require("gitlab.summary")
local keymaps = require("gitlab.keymaps") local keymaps = require("gitlab.keymaps")
@@ -38,7 +39,7 @@ M.setup = function(args)
local command = string.format("cd %s && make", state.BIN_PATH) local command = string.format("cd %s && make", state.BIN_PATH)
local installCode = os.execute(command .. "> /dev/null") local installCode = os.execute(command .. "> /dev/null")
if installCode ~= 0 then if installCode ~= 0 then
require("notify")("Could not install gitlab.nvim! Do you have Go installed?", "error") notify("Could not install gitlab.nvim! Do you have Go installed?", "error")
return return
end end
end end
@@ -64,7 +65,7 @@ M.setup = function(args)
if projectData[1] ~= nil then if projectData[1] ~= nil then
local parsed_ok, data = pcall(vim.json.decode, projectData[1]) local parsed_ok, data = pcall(vim.json.decode, projectData[1])
if parsed_ok ~= true then if parsed_ok ~= true then
require("notify")("Failed calling setup. Could not get project data.", "error") notify("Failed calling setup. Could not get project data.", "error")
else else
state.INFO = data state.INFO = data
end end

View File

@@ -1,4 +1,5 @@
local state = require("gitlab.state") local state = require("gitlab.state")
local notify = require("notify")
local function get_git_root() local function get_git_root()
local output = vim.fn.system('git rev-parse --show-toplevel 2>/dev/null') local output = vim.fn.system('git rev-parse --show-toplevel 2>/dev/null')
@@ -66,14 +67,14 @@ local base_invalid = function()
local current_branch = string.gsub(current_branch_raw, "\n", "") local current_branch = string.gsub(current_branch_raw, "\n", "")
if current_branch == "main" or current_branch == "master" then if current_branch == "main" or current_branch == "master" then
require("notify")('On ' .. current_branch .. ' branch, no MRs available', "error") notify('On ' .. current_branch .. ' branch, no MRs available', "error")
return true return true
end end
local base = state.BASE_BRANCH local base = state.BASE_BRANCH
local hasBaseBranch = feature_branch_exists(base) local hasBaseBranch = feature_branch_exists(base)
if not hasBaseBranch then if not hasBaseBranch then
require("notify")('No base branch. If this is a Gitlab repository, please check your setup function!', "error") notify('No base branch. If this is a Gitlab repository, please check your setup function!', "error")
return true return true
end end
end end
@@ -153,13 +154,13 @@ end
local function print_success(_, line) local function print_success(_, line)
if line ~= nil and line ~= "" then if line ~= nil and line ~= "" then
require("notify")(line, "info") notify(line, "info")
end end
end end
local function print_error(_, line) local function print_error(_, line)
if line ~= nil and line ~= "" then if line ~= nil and line ~= "" then
require("notify")(line, "error") notify(line, "error")
end end
end end