folke / trouble.nvim

🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.
Apache License 2.0
5.24k stars 178 forks source link

feature: allow user to set winid #346

Closed distek closed 4 months ago

distek commented 9 months ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

If the buffer for trouble is moved to a different window, the View:get_cursor() fails (along with some other internals).

Describe the solution you'd like

A way to rather set the window ID for the view object, or have trouble determine what the current window is based on which window has the buffer open (if only one, or use the first one it finds?).

Allowing the user to set is likely the safer option, I'd imagine.

Describe alternatives you've considered

n/a

Additional context

Adding the following works just fine:

diff --git a/lua/trouble/init.lua b/lua/trouble/init.lua
index 140b311..564c18d 100644
--- a/lua/trouble/init.lua
+++ b/lua/trouble/init.lua
@@ -297,4 +297,12 @@ function Trouble.get_items()
   end
 end

+function Trouble.set_win(win)
+  if vim.api.nvim_win_is_valid(win) then
+    view.win = win
+  else
+    vim.error("winid provided is not valid")
+  end
+end
+
 return Trouble

There is the possibility of errors due to the user not managing the window as needed, but the responsibility of such is on the user.

If they're using such a feature, the implication would be they should know what they're doing.

folke commented 4 months ago

Development on the main branch is EOL.

Trouble has been rewritten and will be merged in main soon.

This issue/feature either no longer exists or has been implemented on dev.

For more info, see https://github.com/folke/trouble.nvim/tree/dev