Skip to content

Commit 3968cde

Browse files
fix: Jump to correct column for class-level fixture definitions
scan_fixtures was only storing the row, causing jump/fixture.lua to always land at column 0. For fixtures defined inside a class the def keyword is indented, so column 0 was wrong. Now stores col from func_node:start() and the jump uses it. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent aa1cfa8 commit 3968cde

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

lua/pytrize/jump/fixture.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ M.to_declaration = function()
3232
end
3333

3434
open_file(location.file)
35-
vim.api.nvim_win_set_cursor(0, {location.linenr, 0})
35+
vim.api.nvim_win_set_cursor(0, {location.linenr, location.col})
3636

3737
if require('pytrize.settings').settings.metrics then
3838
local total = hrtime() - t0

lua/pytrize/ts.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ M.scan_fixtures = function(filepath)
9797

9898
local fixtures = {}
9999
for _, def in ipairs(defs) do
100-
local row = def.name_node:start()
100+
local row, col = def.func_node:start()
101101
fixtures[def.name] = {
102102
file = filepath,
103103
linenr = row + 1,
104+
col = col,
104105
}
105106
end
106107

tests/pytrize/ts_spec.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,34 @@ describe("scan_fixtures", function()
150150
os.remove(path)
151151
end)
152152

153+
it("returns col=0 for a top-level fixture", function()
154+
local path = write_tmp_py("scan_col_top", {
155+
"import pytest",
156+
"",
157+
"@pytest.fixture",
158+
"def db():",
159+
" return 'connection'",
160+
})
161+
local fixtures = ts_utils.scan_fixtures(path)
162+
assert.are.equal(0, fixtures.db.col)
163+
os.remove(path)
164+
end)
165+
166+
it("returns correct col for a fixture defined inside a class", function()
167+
local path = write_tmp_py("scan_col_class", {
168+
"import pytest",
169+
"",
170+
"class TestFixtures:",
171+
" @pytest.fixture",
172+
" def class_fix(self):",
173+
" return 42",
174+
})
175+
local fixtures = ts_utils.scan_fixtures(path)
176+
assert.are.equal(5, fixtures.class_fix.linenr)
177+
assert.are.equal(4, fixtures.class_fix.col)
178+
os.remove(path)
179+
end)
180+
153181
it("cleans up buffer for files that were not previously loaded", function()
154182
local path = write_tmp_py("scan4", {
155183
"import pytest",

0 commit comments

Comments
 (0)