-
-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(popup)!: moved="any"
, enter
default, callback=fn
#622
base: master
Are you sure you want to change the base?
Conversation
@errael I am not too familiar with the codebase itself but I can solve some of the questions To run test:
To make test:
To check code style:
The next thing I am not so sure about, but I think this PR will "break" things in comparison with the |
moved="any"
, enter
default, callback=fn
moved="any"
, enter
default, callback=fn
@AlejandroSuero Thanks so much; very useful. I was going to ask about running just popup tests. But got around to doing the following on the command line
which seemed to work. It's been so many years since I've messed with makefiles... Wanting to use the Makefile to run only popup_spec.lua, this seems to work
and doing
Is there something else that makes sense? I'll include this change in the PR, can always take it out. One test, out of all the tests, is failing. Is this something to file an issue about? |
@errael to test single files you can change or create a target on the Makefile, the I will stick to the testing the whole suite in case some other modules make use of popup. Also is what is used on CI. But this something that @Conni2461 and @tjdevries should know better to explain why there is no target for Regarding the test failure, right now Im on my mobile so its a pain to check it tbh, but no ones resolves your question, tomorrow when I wake I see what could be the point of failure 😊 |
I've added some tests. I've run into a problem. In particular Here's the use case
The code can be seen in popup_spec.lua around line 195 in the PR after
|
What I'm seeing
|
Make it ready for review. Test Test |
@errael The principal issue I see is that In my case, Here is the error that Fail || plenary.popup moved option without moved
.../aome/personal/plenary.nvim/tests/plenary/popup_spec.lua:179: attempt to call global 'async' (a nil value)
stack traceback:
.../path/to/plenary.nvim/tests/plenary/popup_spec.lua:179: in function <.../path/to/plenary.nvim/tests/plenary/popup_spec.lua:178>
Fail || plenary.popup moved option with moved
.../path/to/plenary.nvim/tests/plenary/popup_spec.lua:195: attempt to call global 'async' (a nil value)
stack traceback:
.../path/to/plenary.nvim/tests/plenary/popup_spec.lua:195: in function <.../path/to/plenary.nvim/tests/plenary/popup_spec.lua:194> |
You can use either Some examples in Also in |
@errael I made the following changes, in case you want me to commit it to your branch. -- at the top
require("plenary.async").tests.add_to_env() -- this lets you use the `a` variable to make it async
-- ...
a.describe("moved option", function()
local function populate()
local wnr = vim.fn.winnr()
local bnr = vim.fn.winbufnr(wnr)
vim.fn.setbufline(bnr, 1, {"one", "two", "three", "four"})
vim.fn.cursor(1, 1)
end
local callback_result
local function callback(wid, result)
callback_result = result
end
a.it("without moved", function()
-- removed aync()
callback_result = nil
populate()
local win_id = popup.create("hello there", {
callback = callback,
})
-- move the cursor, should not do callback
vim.fn.cursor(2, 1)
local timer = vim.uv.new_timer() -- declared timer
timer:start(10, 0, function()
eq(nil, callback_result)
vim.api.nvim_win_close(win_id, true)
end)
-- removed done()
end)
a.it("with moved", function()
-- removed async()
callback_result = nil
populate()
local win_id = popup.create("hello there", {
moved = "any",
callback = callback,
})
-- move the cursor, window closes and callback invoked
vim.fn.cursor(2, 1)
local timer = vim.uv.new_timer() -- declared timer
timer:start(10, 0, function()
eq(-1, callback_result)
if -1 ~= callback_result then
-- window wasn't closed
vim.api.nvim_win_close(win_id, true)
end
-- removed done()
end)
end)
end) |
Cool.
Thanks for the notes on using async. I'll take a look at the references you provided; appreciated. So the No need to do the commit, thanks for taking a look. So much new stuff ... |
(I'm looking at adding
mousemoved='any'
,close='click'
, andpopup_close()
to popups; came across a few things to fix first.)To reviewers
This is my first
neovim
related PR and my firstlua
code. Suggestions about style... welcome. Not sure how this repo handles reviews, so I'm tagging some names that have done some popup work (sorry for the noise). There's some TODO I scattered which I'll remove before taking out of draft, looking for feedback. Note: haven't yet looked at tests; wonder how to run locally. There's a probable bug in tbl.apply_defaults, noted in popup/utils.lua.@l-kershaw @fdschmidt93 @AlejandroSuero @xactlyblue @jesseleite
@Conni2461 @tjdevries
Fix
moved = 'any'
option.Before this PR, the popup option "moved = 'any'," gets an exception because of changes made to vim.lsp.util.close_preview_autocmd:
Those changes looks like a fix. The now private code from "...lsp.util" is copied in here and the the buffer numbers are added as needed for the new code.
Default the new option
enter
tofalse
Changed the default to false, so the behavior matches
vim
with no options; which is to leave the cursor where it was and not change the focus to the popup. Is there a place to note breaking changes? Wonder the reason for "enter" option?Fix callback
I couldn't get it to work in a simple case. Converted to an autocmd. Comments on potential timing issues? Accessing buffer in callback does work. There's some preliminary work to support "popup_close(win_id, result)" and mouse stuff for a later PR.
Update POPUP.md
Could also do ...
There's dict_default(). Would using tbl.apply_defaults make sense? Seems cleaner.
Should tbl.apply_defaults do a deepcopy of any table from defaults?
There was a comment around the callback setup.
I've removed the comment. The called back function may want to know the win_id; for example,
there could be a data structure associated with the win_id that can be freed.
PS: For the stuff I'm looking at adding, I could open a discussion or just do the PR and discuss there; recommendation?