forked from AckslD/nvim-pytrize.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixture.lua
More file actions
32 lines (26 loc) · 831 Bytes
/
fixture.lua
File metadata and controls
32 lines (26 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
local M = {}
local warn = require('pytrize.warn').warn
local open_file = require('pytrize.jump.util').open_file
local paths = require('pytrize.paths')
local ts_utils = require('pytrize.ts')
M.to_declaration = function()
local fixture = vim.fn.expand('<cword>')
if fixture == '' then
warn('no word under cursor')
return
end
local filepath = vim.api.nvim_buf_get_name(0)
local root_dir = paths.split_at_root(filepath)
if root_dir == nil then
return
end
local fixtures = ts_utils.build_fixture_index(filepath, root_dir)
local location = fixtures[fixture]
if location == nil then
warn(string.format('fixture "%s" not found', fixture))
return
end
open_file(location.file)
vim.api.nvim_win_set_cursor(0, {location.linenr, 0})
end
return M