Skip to content

Commit 1be79c2

Browse files
committed
Try yet again to fix the import/build bug without introducing flakiness.
1 parent 69834cb commit 1be79c2

3 files changed

Lines changed: 15 additions & 45 deletions

File tree

lua/lean/infoview.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,12 +1653,15 @@ end
16531653

16541654
---@private
16551655
---Called by the $/lean/fileProgress handler.
1656-
---Only updates pins whose processing state at their position has changed.
1656+
---Skips updates only when the pin's position is not being processed
1657+
---and was already not being processed on the last notification.
1658+
---During processing, every notification may carry new diagnostics
1659+
---(e.g. lake build output) worth re-rendering.
16571660
function infoview.__on_file_progress(uri)
16581661
for _, each in pairs(infoview._by_tabpage) do
16591662
for _, pin in pairs(each:pins_for(uri)) do
1660-
local current = progress.at_or_file(pin.__position_params)
1661-
if current ~= pin.__last_processing then
1663+
local current = progress.at(pin.__position_params)
1664+
if current ~= nil or pin.__last_processing ~= nil then
16621665
pin.__last_processing = current
16631666
pin:request_update()
16641667
end

lua/lean/progress.lua

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,42 +46,6 @@ function M.at(params)
4646
return info and (info.kind or M.Kind.processing)
4747
end
4848

49-
---Like `at`, but also returns processing if the file has processing
50-
---ranges that haven't reached the given position yet.
51-
---This is needed when e.g. imports are building and the cursor is on a
52-
---later line that hasn't been reached yet.
53-
---@param params lsp.TextDocumentPositionParams
54-
---@return LeanFileProgressKind? kind
55-
function M.at_or_file(params)
56-
local infos = M.proc_infos[params.textDocument.uri]
57-
if not infos then
58-
return M.Kind.processing
59-
end
60-
if #infos == 0 then
61-
return
62-
end
63-
64-
local line = params.position.line
65-
---@type LeanFileProgressProcessingInfo?
66-
local info = vim.iter(infos):find(function(each)
67-
return (line >= each.range.start.line) and (line <= each.range['end'].line)
68-
end)
69-
if info then
70-
return info.kind or M.Kind.processing
71-
end
72-
73-
-- Cursor is not in any processing range. If processing hasn't reached
74-
-- the cursor yet (cursor is past all ranges), treat as processing.
75-
-- Lean processes top-to-bottom, so this means the cursor's line is
76-
-- waiting for earlier lines (e.g. imports) to finish.
77-
local max_end = vim.iter(infos):fold(-1, function(acc, each)
78-
return math.max(acc, each.range['end'].line)
79-
end)
80-
if line > max_end then
81-
return M.Kind.processing
82-
end
83-
end
84-
8549
---Calculate the percentage of a buffer which finished processing.
8650
---@param bufnr? number the buffer number, defaulting to 0
8751
---@return number the percentage of *finished* lines as a number from 0 to 100

spec/infoview/contents_spec.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,11 @@ describe('interactive infoview', function()
520520
)
521521

522522
describe(
523-
'file progress updates when cursor is not on a processing line',
524-
helpers.clean_buffer('#eval IO.sleep 5000\n\n#check (37 : Nat)', function()
525-
helpers.move_cursor { to = { 3, 0 } }
526-
helpers.wait:for_file_processing()
527-
523+
'file progress updates',
524+
helpers.clean_buffer('#check (37 : Nat)', function()
528525
it('does not trigger redundant updates for unchanged progress', function()
526+
helpers.wait:for_processing()
527+
529528
local uri = vim.uri_from_bufnr(0)
530529
local pin = infoview.get_current_infoview().pin
531530

@@ -543,7 +542,11 @@ describe('interactive infoview', function()
543542
assert.are.equal(0, update_count)
544543

545544
-- But a genuine state change does trigger an update.
546-
require('lean.progress').proc_infos[uri] = {}
545+
require('lean.progress').proc_infos[uri] = {
546+
{
547+
range = { start = { line = 0, character = 0 }, ['end'] = { line = 0, character = 0 } },
548+
},
549+
}
547550
infoview.__on_file_progress(uri)
548551
assert.are.equal(1, update_count)
549552

0 commit comments

Comments
 (0)