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,7 +343,6 @@ local function handler(_, _, result)
if result == nil then return end
D.state.code_win = vim.api.nvim_get_current_win()
if D.state.outline_buf == nil then
setup_buffer()
D.state.outline_items = parse(result)
D.state.flattened_outline_items = flatten(parse(result))
@@ -355,13 +354,15 @@ local function handler(_, _, result)
D.state.outline_win)
write_details(D.state.outline_buf, details)
setup_highlights()
else
vim.api.nvim_win_close(D.state.outline_win, true)
end
end
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
function D.setup(opts)