@@ -10,20 +10,37 @@ local function has_value(tab, val)
1010 return false
1111end
1212
13+ --- remove vim special characters from json keys
14+ --- @param key string
15+ --- @return string " parsed key"
16+ local function parse_key (key )
17+ return (key :gsub (" /" , " \\ /" ))
18+ end
19+
20+ --- return location of key in buffer
21+ --- @param key string
22+ --- @param ft string
23+ --- @return table
1324local function get_key_location (key , ft )
1425 if ft == " json" then
1526 return {
16- row = vim .api .nvim_exec ([[ g/^\s*"]] .. key .. [[ "/echo line('.')]] , true ),
17- col = vim .api .nvim_exec ([[ g/^\s*"]] .. key .. [[ "/execute "normal! ^" | echo col('.')-1]] , true ),
27+ row = vim .api .nvim_exec ([[ g/^\s*"]] .. parse_key ( key ) .. [[ "/echo line('.')]] , true ),
28+ col = vim .api .nvim_exec ([[ g/^\s*"]] .. parse_key ( key ) .. [[ "/execute "normal! ^" | echo col('.')-1]] , true ),
1829 }
1930 elseif ft == " yaml" then
2031 return {
21- row = vim .api .nvim_exec ([[ g/^]] .. key .. [[ /echo line('.')]] , true ),
22- col = vim .api .nvim_exec ([[ g/^]] .. key .. [[ /execute "normal! ^" | echo col('.')]] , true ),
32+ row = vim .api .nvim_exec ([[ g/^]] .. parse_key ( key ) .. [[ /echo line('.')]] , true ),
33+ col = vim .api .nvim_exec ([[ g/^]] .. parse_key ( key ) .. [[ /execute "normal! ^" | echo col('.')]] , true ),
2334 }
35+ else
36+ return {}
2437 end
2538end
2639
40+ --- fetch json keys for cur buf and populate qf list
41+ --- @param ft string
42+ --- @param type string variable type to fetch if given
43+ --- @param sort boolean sort list alphabetically
2744local function populate_qf (ft , type , sort )
2845 local cmd_lines = {}
2946 local cur_file = vim .fn .getreg (" %" )
0 commit comments