fix: Handle toggling logic outside the handler

* This way we can close the window while being focused in it. Before,
  the window was not closed because the handler wasn't called because no
  lsp was attached
This commit is contained in:
simrat39
2021-04-21 22:26:01 -07:00
parent 3381bfeea6
commit 7f37dfa7fd

View File

@@ -343,25 +343,26 @@ local function handler(_, _, result)
if result == nil then return end if result == nil then return end
D.state.code_win = vim.api.nvim_get_current_win() D.state.code_win = vim.api.nvim_get_current_win()
if D.state.outline_buf == nil then setup_buffer()
setup_buffer() D.state.outline_items = parse(result)
D.state.outline_items = parse(result) D.state.flattened_outline_items = flatten(parse(result))
D.state.flattened_outline_items = flatten(parse(result))
local lines = get_lines(D.state.flattened_outline_items) local lines = get_lines(D.state.flattened_outline_items)
write_outline(D.state.outline_buf, lines) write_outline(D.state.outline_buf, lines)
local details = get_details(D.state.outline_items, D.state.outline_buf, local details = get_details(D.state.outline_items, D.state.outline_buf,
D.state.outline_win) D.state.outline_win)
write_details(D.state.outline_buf, details) write_details(D.state.outline_buf, details)
setup_highlights() setup_highlights()
else
vim.api.nvim_win_close(D.state.outline_win, true)
end
end end
function D.toggle_outline() function D.toggle_outline()
vim.lsp.buf_request(0, "textDocument/documentSymbol", getParams(), handler) if D.state.outline_buf == nil then
vim.lsp.buf_request(0, "textDocument/documentSymbol", getParams(),
handler)
else
vim.api.nvim_win_close(D.state.outline_win, true)
end
end end
function D.setup(opts) function D.setup(opts)