Revert "feat(parser): Flatten outline items while parsing"

This reverts commit 776ddb3930.
This commit is contained in:
Simrat Grewal
2022-08-16 17:59:47 -07:00
parent 7aadfaf916
commit 057715f3b0
6 changed files with 34 additions and 21 deletions

View File

@@ -20,7 +20,7 @@ end
function M.show_code_actions()
local current_line = vim.api.nvim_win_get_cursor(main.state.outline_win)[1]
local node = main.state.outline_items[current_line]
local node = main.state.flattened_outline_items[current_line]
local params = get_action_params(node, main.state.code_win)
vim.lsp.buf_request(

View File

@@ -17,7 +17,7 @@ end
-- handler yoinked from the default implementation
function M.show_hover()
local current_line = vim.api.nvim_win_get_cursor(so.view.winnr)[1]
local node = so.state.outline_items[current_line]
local node = so.state.flattened_outline_items[current_line]
local hover_params = get_hover_params(node, so.state.code_win)

View File

@@ -24,7 +24,7 @@ local function parse_result(result, depth, hierarchy)
-- whether this node is the last in its group
local isLast = index == #result
local children = {}
local children = nil
if value.children ~= nil then
-- copy by value because we dont want it messing with the hir table
local child_hir = t_utils.array_copy(hir)
@@ -54,15 +54,11 @@ local function parse_result(result, depth, hierarchy)
character = selectionRange.start.character,
range_start = range.start.line,
range_end = range['end'].line,
-- children = children,
children = children,
depth = level,
isLast = isLast,
hierarchy = hir,
})
for _, node in pairs(children) do
table.insert(ret, node)
end
end
end
return ret
@@ -143,11 +139,25 @@ function M.parse(response)
return parse_result(sorted, nil, nil)
end
function M.get_lines(outline_items)
function M.flatten(outline_items)
local ret = {}
for _, value in ipairs(outline_items) do
table.insert(ret, value)
if value.children ~= nil then
local inner = M.flatten(value.children)
for _, value_inner in ipairs(inner) do
table.insert(ret, value_inner)
end
end
end
return ret
end
function M.get_lines(flattened_outline_items)
local lines = {}
local hl_info = {}
for node_line, node in ipairs(outline_items) do
for node_line, node in ipairs(flattened_outline_items) do
local line = t_utils.str_to_table(string.rep(' ', node.depth))
local running_length = 1
@@ -213,9 +223,9 @@ function M.get_lines(outline_items)
return lines, hl_info
end
function M.get_details(outline_items)
function M.get_details(flattened_outline_items)
local lines = {}
for _, value in ipairs(outline_items) do
for _, value in ipairs(flattened_outline_items) do
table.insert(lines, value.detail or '')
end
return lines

View File

@@ -15,7 +15,7 @@ end
function M.rename()
local current_line = vim.api.nvim_win_get_cursor(so.view.winnr)[1]
local node = so.state.outline_items[current_line]
local node = so.state.flattened_outline_items[current_line]
local params = get_rename_params(node, so.state.code_win)

View File

@@ -60,12 +60,12 @@ end
-- runs the whole writing routine where the text is cleared, new data is parsed
-- and then written
function M.parse_and_write(bufnr, outline_items)
local lines, hl_info = parser.get_lines(outline_items)
function M.parse_and_write(bufnr, flattened_outline_items)
local lines, hl_info = parser.get_lines(flattened_outline_items)
M.write_outline(bufnr, lines)
clear_virt_text(bufnr)
local details = parser.get_details(outline_items)
local details = parser.get_details(flattened_outline_items)
M.add_highlights(bufnr, hl_info)
M.write_details(bufnr, details)
end