Skip to content

Commit d4b66da

Browse files
async job finder: correctly handle files not ending in newline
fixes #2517
1 parent a4ed825 commit d4b66da

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

lua/telescope/_.lua

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,17 @@ function LinesPipe:iter(schedule)
159159
index = nil
160160

161161
local read = self:read()
162-
if previous == nil and read == nil then
163-
return
162+
if read == nil then
163+
if previous == nil then
164+
return nil, true
165+
elseif #previous > 0 then
166+
-- the file doesn't end in a newline. flush the line contents we had and finish.
167+
return previous .. "\n", true
168+
end
164169
end
165170

166171
read = string.gsub(read or "", "\r", "")
167-
return (previous or "") .. read
172+
return (previous or "") .. read, false
168173
end
169174

170175
local next_value = nil
@@ -181,8 +186,19 @@ function LinesPipe:iter(schedule)
181186
index = string.find(text, "\n", index, true)
182187

183188
if index == nil then
184-
text = get_next_text(string.sub(text, start or 1))
185-
return next_value()
189+
local is_done
190+
text, is_done = get_next_text(string.sub(text, start or 1))
191+
if is_done and text ~= nil then
192+
local res = text
193+
text = nil
194+
index = nil
195+
if schedule then
196+
async.util.scheduler()
197+
end
198+
return res
199+
else
200+
return next_value()
201+
end
186202
end
187203

188204
index = index + 1

0 commit comments

Comments
 (0)