Post B438T8Gig5zOkr1Zcu by ity@estradiol.city
(DIR) More posts by ity@estradiol.city
(DIR) Post #B438T8Gig5zOkr1Zcu by ity@estradiol.city
0 likes, 0 repeats
Off-by-one errors are HORRIBLE HORRIBLE HORRIBLE HORRIBLE HORRIBLE. 2h down the drain debugging THIS. local range = {node:range()} local loc = {pos[1]-1, pos[2]} if (loc[1] > range[1] and loc[1] < range[3]) or (((loc[1] == range[1] and loc[2] >= range[2]) and (loc[1] ~= range[3])) and not (range[1] == range[3])) or (((loc[1] == range[3] and loc[2] < range[4]) and (loc[1] ~= range[1])) and not (range[1] == range[3])) or ((range[1] == range[3]) and (loc[1] == range[1]) and (loc[2] >= range[2] and loc[2] < range[4])) then ret = node end
(DIR) Post #B438T8Y5dVsrcj9RhY by Paradox@raru.re
0 likes, 0 repeats
@ity There's gotta be something doable about this logic flow. Fuuuuuck.
(DIR) Post #B474aGrjUTNoGDKDq4 by ity@estradiol.city
0 likes, 0 repeats
@Paradox I can't think of anything but I'm also a horrible programmerAnd wrote this in the middle of the night iirc. Maybe in a better mind state I'd think of smth (I'm sick rn so no coding for me)
(DIR) Post #B47AQO92AiDJfJ5YHo by Paradox@raru.re
0 likes, 0 repeats
@ity Just to clarify somethingLoc is x, yRange is xmin, ymin, xmax, ymaxI'm guessing?
(DIR) Post #B47AzdOrReA978IXoG by Paradox@raru.re
0 likes, 0 repeats
@ity Hey it's fine. ^_^
(DIR) Post #B47NUPvim6b9lT7464 by ity@estradiol.city
0 likes, 0 repeats
@Paradox I can post the whole code soon™, it's neovim Lua treesitter stuff, where loc/pos is cursor position and range is the range of a parsed node (I'm checking if the cursor is inside a node, to find which of many nodes of a specific type it is in, if any)
(DIR) Post #B49J41kQ3ByljcuJ3w by Paradox@raru.re
0 likes, 0 repeats
@ity Xstuck = (range[1] == range[3])x_inrange_exc = (loc[1] > range[1] and loc[1] < range[3])Xmin = (loc[1] == range[1])Xmax = (loc[1] == range[3])Y_GEQmin = (loc[2] >= range[2])Y_LTmax = (loc[2] < range[4])if x_inrange_excor(((Xmin and Y_GEQmin) and not Xmax) and not Xstuck)or(((Xmax and Y_LTmax) and not Xmin) and not Xstuck)or(Xstuck and Xmin and (Y_GEQmin and Y_LTmax))Feel free to ask about stuff. Tried to make variable names that were clear without being verbose.
(DIR) Post #B4BTwk8UcTjStjoglM by ity@estradiol.city
0 likes, 0 repeats
@Paradox function find_loc(type, pos) local parser = vim.treesitter.get_parser(1, "lua") local ret = nil if parser:parse(true, function(err, trees) if err ~= nil then error(err) end local tree = trees[1] local query = vim.treesitter.query.parse("lua", [[ (]]..type..[[) @capture ]]) for id, node, metadata, match in query:iter_captures(tree:root(), 1) do local range = {node:range()} local loc = {pos[1]-1, pos[2]} if (loc[1] > range[1] and loc[1] < range[3]) or (((loc[1] == range[1] and loc[2] >= range[2]) and (loc[1] ~= range[3])) and not (range[1] == range[3])) or (((loc[1] == range[3] and loc[2] < range[4]) and (loc[1] ~= range[1])) and not (range[1] == range[3])) or ((range[1] == range[3]) and (loc[1] == range[1]) and (loc[2] >= range[2] and loc[2] < range[4])) then ret = node end end end) == nil then error("Returned nil") end return retendfunction find_dir_childs(par_node, type) local parser = vim.treesitter.get_parser(1, "lua") local ret = nil if parser:parse(true, function(err, trees) if err ~= nil then error(err) end local tree = trees[1] local query = vim.treesitter.query.parse("lua", [[ (]]..type..[[) @capture ]]) local res_list = {} for id, node, metadata, match in query:iter_captures(tree:root(), 1) do if node:parent():equal(par_node) then table.insert(res_list, node) end end ret = res_list end) == nil then error("Returned nil") end return retendvim.print(":", find_dir_childs(find_loc("table_constructor", vim.api.nvim_win_get_cursor(0)), "field"), ":")Finally got to sending the entire Lua file (tho it's all testing stuff for my neovim fork & plugin stuff)
(DIR) Post #B4BTwkKBuz5dU1I1zs by Paradox@raru.re
0 likes, 0 repeats
@ity I'm just gonna focus on the loc and range bit, but this helped me figure out what kind of node it is.So I was right about what range looks like.There's some indication that it's zero indexed, but I can't find official docs about this.