Open tekjar opened 3 years ago
I would like a similar feature, maybe make the logs as a toggle-able floating window
@tekjar because you can set the open_cmd
for the log buffer so that rather that being a split it's whatever a user wants e.g. a full screen window or tab etc. this means that making it "toggle-able" is difficult. For example, if a user has an open_cmd
of 30vsplit
how would that be toggled since if they used the toggle command that window was already open they would create a new split, even if it wasn't open in that tab but was open in another then what? I guess one solution would be to save the window number and try to jump to that window if it was open anywhere 🤔 not sure if that would work though
Regarding floating windows for logs, I think that's not really related and tbh I don't think I will add that since I think floating windows aren't a suitable UI for looking at logs and I don't think everything needs to go into one, the pattern is a little overused IMO.
I was trying to implement this by fetching the buffer whose name would have "FLUTTER_LOG", I couldn't implement it due to lack of knowledge and time, but maybe that could be a feasible way? To check whether such a buffer exists, if it does, open it with what ever open_cmd
was and check for a window number if it is already open close it. I am not sure, I am completely guessing at this point.
I don't understand much about open_cmd
and 30vsplit
. But intuition was that if widget tree can be toggled, logs can also be toggled. Right now, if I close the logs window (vsplit). I don't have any way to bring it back. FlutterRun
just shows Flutter is already running
notification without opening logs vsplit again
Edit: Looks like I can access these things with vim buffers. :buffers
@tekjar @Chaitanyabsprip Currently I'm using this to toggle the devlog -- probably not the best solution but works nonetheless. @akinsho I'm happy to make a PR if you think something like this should be included out-of-the-box.
local api = vim.api
local M = {}
M.toggle_log = function()
local wins = api.nvim_list_wins()
for _, id in pairs(wins) do
local bufnr = api.nvim_win_get_buf(id)
if api.nvim_buf_get_name(bufnr):match '.*/([^/]+)$' == '__FLUTTER_DEV_LOG__' then
return vim.api.nvim_win_close(id, true)
end
end
pcall(function()
vim.api.nvim_command 'sb + __FLUTTER_DEV_LOG__ | resize 15'
end)
end
return M
@rlch the reason I don't want to really entertain the idea of "toggling" the dev log is that it can be opened in any possible way that nvim allows opening a buffer so the whole idea of toggling is quite complex since you might be toggling a tab or a split or it might replace the current window, which means it's quite hard to know what is being opened or closed. I did look into this at some point last year and it proved to be quite complex to try and cover all these cases. The above command would work if you opened a split but not if you opened this buffer using a tab.
@rlch the reason I don't want to really entertain the idea of "toggling" the dev log is that it can be opened in any possible way that nvim allows opening a buffer so the whole idea of toggling is quite complex since you might be toggling a tab or a split or it might replace the current window, which means it's quite hard to know what is being opened or closed. I did look into this at some point last year and it proved to be quite complex to try and cover all these cases. The above command would work if you opened a split but not if you opened this buffer using a tab.
I see! Thanks for the information, guess I'll leave my solution there for now as my usecase for opening the dev log is restricted to splits.
Feel free to close it; but I'll start a draft PR for this feature in-case anyone wants to build upon what I've worked on so far. Note that I've changed it a bit from the solution above to use your API.
@akinsho would it be possible to add suggested log toggling solution out of the box for split buffers (i.e. not tabs) only? I think it's safe to assume that most people will use default or horizontal/veritcal split for dev log. I'm not sure what would be the pattern of using logs opened in tabs, but clearly toggling is not that important (or even needed?) there.
@rlch's sample works nice, just needs to respect outline.open_cmd
setting. Would love to have this out of the box.
@divan or anyone else willing to put in the work for a solution I'm happy to work with them on a PR, I don't love the idea of a half solution i.e. works for splits but not other types of view because whilst it would solve everyone here's issues I'll undoubtedly get even more issues from someone else using a tab layout it doesn't work for 😓. Since it makes sense in the context of splits, I'm happy to have a split based toggle log command that is explicitly for splits e.g. FlutterDevLogToggleSplit
etc.
Tbh I've spent most of my Sunday so far dealing with issues and debugging configs across multiple plugins (big mistake to make this many projects) so if someone wants to contribute please be my guest, I definitely don't have capacity to tackle this atm.
@akinsho I'd love to contribute, but I don't have capacity to learn neovim internals and lua right now, just to make this work. :/ Take your time, find co-maintainer or whatever is needed to keep this awesome plugin afloat, and congrats with a new job, hope it's rewarding.
As per half solution – is there anyone who uses dev logs in a tab? What does it even mean "to toggle a tab", then? :) If I understand correctly, toggling makes sense only for splits.
To complicate things a bit more – as I work on ultra-wide monitor (32:9), I sometimes want to open additional windows (like diagnostics or quickfix, and flutter dev logs) in a vertical split, but be able to switch to the horizontal split. So currently I use cloned version of @rlch function that takes open_cmd as an argument, and configure vertical/horizontal toggling to my taste. Works pretty nice so far.
Just to clarify, the reason why the format of the logs is variable is because people have varying use cases and situations. Working on a small screen or laptop etc. having your flutter logs in a split is not adequate, I frequently work on just a laptop and trying to figure out what the logs say on a 14-inch screen split in two is a nightmare.
So I don't think any solution will involve taking that functionality away (not that that was being suggested)
@akinsho true. So can we narrow down use cases to 1. Split screen and 2. Tabs? Or there are more?
Do you agree that toggling doesn't make sense for tab use case?
@divan that makes sense if someone is showing the logs in the tab then it's already out of the way so toggling it to make space or get more screen space isn't that helpful/unblock toggling for splits
When I execute
:FlutterRun
, logs window is created and I could hot reload. This logs window is some times a distraction. Is there a command to easily toggle it on and off?