Skip to content

Commit 57f4ae4

Browse files
authored
Merge pull request #268 from Isrothy/fix-267
fix: Error in coroutine
2 parents 9a40d41 + 8029872 commit 57f4ae4

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lua/neominimap/buffer/internal.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ M.internal_render_co = function(bufnr)
8686
end
8787

8888
co.defer_co()
89+
if not api.nvim_buf_is_valid(bufnr) then
90+
return
91+
end
8992

9093
local tabwidth = vim.bo[bufnr].tabstop
9194

@@ -94,6 +97,9 @@ M.internal_render_co = function(bufnr)
9497
local minimap = text.gen_co(lines, tabwidth)
9598

9699
co.defer_co()
100+
if not api.nvim_buf_is_valid(bufnr) then
101+
return
102+
end
97103

98104
vim.bo[mbufnr_].modifiable = true
99105

@@ -104,6 +110,9 @@ M.internal_render_co = function(bufnr)
104110
vim.bo[mbufnr_].modifiable = false
105111

106112
co.defer_co()
113+
if not api.nvim_buf_is_valid(bufnr) then
114+
return
115+
end
107116

108117
vim.api.nvim_exec_autocmds("User", {
109118
group = "Neominimap",
@@ -119,6 +128,9 @@ M.internal_render_co = function(bufnr)
119128
local highlights = treesitter.extract_highlights_co(bufnr)
120129

121130
co.defer_co()
131+
if not api.nvim_buf_is_valid(bufnr) then
132+
return
133+
end
122134

123135
treesitter.apply_co(mbufnr_, highlights)
124136
logger.log.trace("Treesitter diagnostics for buffer %d generated successfully", bufnr)

lua/neominimap/map/treesitter.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ M.extract_highlights_co = function(bufnr)
170170
highlights[row] = line
171171
end)
172172
co.defer_co()
173+
if not api.nvim_buf_is_valid(bufnr) then
174+
return {}
175+
end
173176

174177
local fold = require("neominimap.map.fold")
175178
local coord = require("neominimap.map.coord")
@@ -204,13 +207,19 @@ M.extract_highlights_co = function(bufnr)
204207
end
205208
end)
206209
co.defer_co()
210+
if not api.nvim_buf_is_valid(bufnr) then
211+
return {}
212+
end
207213

208214
co.for_co(1, minimap_height, 1, 5000, function(y)
209215
for x = 1, minimap_width do
210216
highlights[y][x] = most_commons(highlights[y][x].groups)
211217
end
212218
end)
213219
co.defer_co()
220+
if not api.nvim_buf_is_valid(bufnr) then
221+
return {}
222+
end
214223

215224
---@type Neominimap.MinimapHighlight[]
216225
local ret = {}

0 commit comments

Comments
 (0)