Skip to content

Commit

Permalink
fix: improve matching pair detection accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 committed Dec 19, 2024
1 parent 0b3511d commit aa38e49
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
10 changes: 7 additions & 3 deletions lua/precognition/sim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ local function check_pos(string, col, default_config)
for _, motion_name in ipairs(locations) do
local motion_key = default_config[motion_name].text
vim.fn.setcursorcharpos(2, col)
local start_col = vim.fn.getcursorcharpos(0)[3]
vim.api.nvim_feedkeys(motion_key, "x", true)
local cur_pos = vim.fn.getcursorcharpos(0)
if cur_pos[2] == 2 then
if motion_name == "MatchingPair" and cur_pos[3] ~= col then
result[motion_name] = cur_pos[3]
if motion_name == "MatchingPair" then
if cur_pos[3] ~= start_col then
result[motion_name] = cur_pos[3]
end
else
result[motion_name] = cur_pos[3]
end
Expand All @@ -47,7 +50,8 @@ end

M.check = function(line, col)
local remote = get_remote()
return remote.lua_func(check_pos, line, col, require("precognition").default_hint_config)
local result = remote.lua_func(check_pos, line, col, require("precognition").default_hint_config)
return result
end

return M
10 changes: 5 additions & 5 deletions tests/precognition/e2e_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe("e2e tests", function()
end

eq(vim.api.nvim_win_get_cursor(0)[1] - 1, extmarks[1])
eq("b% e w $", extmarks[3].virt_lines[1][1][1])
eq("b e w $", extmarks[3].virt_lines[1][1][1])
eq("PrecognitionHighlight", extmarks[3].virt_lines[1][1][2])
eq({ link = "Comment" }, vim.api.nvim_get_hl(0, { name = extmarks[3].virt_lines[1][1][2] }))

Expand All @@ -75,7 +75,7 @@ describe("e2e tests", function()
})

eq(vim.api.nvim_win_get_cursor(0)[1] - 1, extmarks[1])
eq("b % e w $", extmarks[3].virt_lines[1][1][1])
eq("b e w $", extmarks[3].virt_lines[1][1][1])

vim.api.nvim_win_set_cursor(0, { 2, 1 })
precognition.on_cursor_moved()
Expand All @@ -101,7 +101,7 @@ describe("e2e tests", function()
end

eq(vim.api.nvim_win_get_cursor(0)[1] - 1, extmarks[1])
eq("b% e w", extmarks[3].virt_lines[1][1][1])
eq("b e w", extmarks[3].virt_lines[1][1][1])

vim.api.nvim_win_set_cursor(0, { 4, 1 })
precognition.on_cursor_moved()
Expand Down Expand Up @@ -166,7 +166,7 @@ describe("e2e tests", function()
end

eq(vim.api.nvim_win_get_cursor(0)[1] - 1, extmarks[1])
eq("b% e w $", extmarks[3].virt_lines[1][1][1])
eq("b e w $", extmarks[3].virt_lines[1][1][1])
eq("PrecognitionHighlight", extmarks[3].virt_lines[1][1][2])
eq({ link = "Function" }, vim.api.nvim_get_hl(0, { name = extmarks[3].virt_lines[1][1][2] }))
end)
Expand Down Expand Up @@ -219,7 +219,7 @@ describe("e2e tests", function()
end

eq(vim.api.nvim_win_get_cursor(0)[1] - 1, extmarks[1])
eq("b% e w $", extmarks[3].virt_lines[1][1][1])
eq("b e w $", extmarks[3].virt_lines[1][1][1])
eq("PrecognitionHighlight", extmarks[3].virt_lines[1][1][2])
eq(customMark, vim.api.nvim_get_hl(0, { name = extmarks[3].virt_lines[1][1][2] }))
end)
Expand Down
4 changes: 2 additions & 2 deletions tests/precognition/inlay_hints_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe("lsp based tests", function()
details = true,
})

eq("b% e w $", extmarks[3].virt_lines[1][1][1])
eq("b e w $", extmarks[3].virt_lines[1][1][1])

vim.lsp.inlay_hint.enable(true, { bufnr = buf })
-- NOTE:The test LSP replies with an inlay hint, that suggest "foo" as line 1, position 4
Expand All @@ -146,7 +146,7 @@ describe("lsp based tests", function()
details = true,
})

eq("b% e w $", extmarks[3].virt_lines[1][1][1])
eq("b e w $", extmarks[3].virt_lines[1][1][1])
end)

after_each(function()
Expand Down

0 comments on commit aa38e49

Please sign in to comment.