Skip to content

Commit 9c38a08

Browse files
committed
Don't count term hovering as a goal in Lean 3.
1 parent ba7562e commit 9c38a08

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

lua/lean/lean3.lua

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ local function upconvert_lsp_goal_to_lean4(response)
4848
local goals = {}
4949
for _, contents in ipairs(response.contents) do
5050
if contents.language == 'lean' and contents.value ~= 'no goals' then
51-
-- strip 'N goals' from the front (which is present for multiple goals)
52-
local rest_of_goals = contents.value:gsub('^%d+ goals?\n', '')
51+
if contents.value:match('') then
52+
-- strip 'N goals' from the front (which is present for multiple goals)
53+
local rest_of_goals = contents.value:gsub('^%d+ goals?\n', '')
5354

54-
repeat
55-
local end_of_goal = _GOAL_MARKER:match_str(rest_of_goals)
56-
table.insert(goals, vim.trim(rest_of_goals:sub(1, end_of_goal)))
57-
if not end_of_goal then break end
58-
rest_of_goals = rest_of_goals:sub(end_of_goal + 1)
59-
until rest_of_goals == ""
55+
repeat
56+
local end_of_goal = _GOAL_MARKER:match_str(rest_of_goals)
57+
table.insert(goals, vim.trim(rest_of_goals:sub(1, end_of_goal)))
58+
if not end_of_goal then break end
59+
rest_of_goals = rest_of_goals:sub(end_of_goal + 1)
60+
until rest_of_goals == ""
61+
end
6062
end
6163
end
6264
return { goals = goals }

lua/tests/infoview/lsp_spec.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ describe('infoview', function()
5454
local text = infoview_lsp_update({7, 10})
5555
assert.has_all(text, {"p q : Prop", "h : p ∨ q", "⊢ q ∨ p"})
5656
end)
57+
58+
it('only counts goals as goals, not hovered terms',
59+
function(_)
60+
-- hover for Lean 3 will also return information about `nat`, which is
61+
-- under the cursor, but we shouldn't count that as a goal.
62+
local text = infoview_lsp_update({3, 14})
63+
assert.equal(text, '▶ 1 goal\n\n⊢ Type 1')
64+
end)
5765
end)
5866

5967
it('lean 4', function()

0 commit comments

Comments
 (0)