@@ -20,6 +20,7 @@ P.default_config = {
2020
2121P .last_status = {
2222 count = " ?" ,
23+ retry = false ,
2324}
2425
2526--- Setup default keymaps for updating Neovim or removing source based on user configuration.
@@ -111,6 +112,14 @@ function P.update_with_changes()
111112 P .show_new_commits (true )
112113end
113114
115+ --- Helper function to retry update
116+ local function update_with_retry ()
117+ if P .last_status .retry then
118+ P .last_status .retry = false
119+ P .update_neovim ()
120+ end
121+ end
122+
114123--- Update Neovim from source and show progress in a floating terminal.
115124--- @param opts table | nil Optional options for the update process (branch , build_type , etc. )
116125function P .update_neovim (opts )
@@ -152,18 +161,22 @@ function P.update_neovim(opts)
152161 callback = function (results )
153162 if results .result_code ~= 0 then
154163 utils .notify (" Neovim update failed with error code: " .. results .result_code , vim .log .levels .ERROR )
164+ utils .ConfirmPrompt (" Remove build directory and try again?" , function ()
165+ P .last_status .count = " ?"
166+ P .last_status .retry = true
167+ P .remove_source_dir ({ source_dir = source_dir .. " /build" })
168+ end )
155169 else
156170 utils .notify (" Neovim update complete!" , vim .log .levels .INFO , true )
157171 utils .notify (" Please restart Neovim for the changes to take effect." , vim .log .levels .INFO )
172+ -- Update the status count
173+ P .last_status .count = " 0"
158174 end
159175 end ,
160176 })
161177
162178 -- Go to insert mode
163179 vim .cmd (" startinsert" )
164-
165- -- Update the status count
166- P .last_status .count = " 0"
167180end
168181
169182--- Remove the Neovim source directory or a custom one.
@@ -185,6 +198,7 @@ function P.remove_source_dir(opts)
185198 if success then
186199 utils .notify (" Successfully removed Neovim source directory: " .. source_dir , vim .log .levels .INFO , true )
187200 utils .notify (" Source directory removed with vim.fs.rm" , vim .log .levels .DEBUG )
201+ update_with_retry ()
188202 return true
189203 else
190204 if not err then
@@ -201,14 +215,17 @@ function P.remove_source_dir(opts)
201215 vim .log .levels .INFO ,
202216 true
203217 )
218+ update_with_retry ()
204219 return true
205220 end
206221 utils .notify (" Failed to remove Neovim source directory: " .. source_dir , vim .log .levels .ERROR )
207222 return false
208223 end
209224
210225 -- Attempt to remove with elevated privileges
211- local rm_msg = " echo Attempting to remove source directory with elevated privileges.\n "
226+ local rm_msg = " echo Attempting to remove "
227+ .. source_dir
228+ .. " directory with elevated privileges.\n "
212229 .. " echo Please authorize sudo and press enter.\n "
213230 local privileged_rm = rm_msg .. " sudo rm -rf " .. source_dir
214231 utils .open_floating_terminal ({
@@ -239,6 +256,7 @@ function P.remove_source_dir(opts)
239256 if success == 0 then
240257 utils .notify (" Successfully removed Neovim source directory: " .. source_dir , vim .log .levels .INFO , true )
241258 utils .notify (" Source directory removed with vim.fn.delete" , vim .log .levels .DEBUG )
259+ update_with_retry ()
242260 return true
243261 else
244262 if not err then
@@ -287,14 +305,14 @@ function P.generate_source_dir(opts)
287305 callback = function (results )
288306 if results .result_code == 0 then
289307 utils .notify (" Neovim source cloned successfully" , vim .log .levels .INFO , true )
308+ -- Set the update count to "0"
309+ P .last_status .count = " 0"
290310 else
291311 utils .notify (" Failed to clone Neovim source: " .. results .result_code , vim .log .levels .ERROR )
312+ P .last_status .count = " ?"
292313 end
293314 end ,
294315 })
295-
296- -- Set the update count to "0"
297- P .last_status .count = " 0"
298316 else
299317 -- Notify the user that the source directory already exists
300318 utils .notify (" Neovim source directory already exists: " .. source_dir , vim .log .levels .WARN )
0 commit comments