-
-
Notifications
You must be signed in to change notification settings - Fork 105
feat: add option for print_var for normal mode attempt to find var under cursor #322
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
feat: add option for print_var for normal mode attempt to find var under cursor #322
Conversation
…on print_var_norm
|
@teddylear since the current behaviour uses normal mode by default if nothing is selected, then optionally visual mode as a fallback, I'm not quite sure what splitting up commands for the two modes will buy us. As of right now, to access both behaviours, the config can be set up like this: vim.keymap.set(
"n", -- normal mode map
"<leader>rv",
":lua require('refactoring').debug.print_var({})<CR>",
{ noremap = true }
)
vim.keymap.set(
"v", -- visual mode map
"<leader>rv",
":lua require('refactoring').debug.print_var({})<CR>",
{ noremap = true }
)With splitting them up, it will be pretty much the same thing but with However, after reading #321, I am realizing that the docs for Also, if we were still to split these, perhaps we could do it with a vim.keymap.set(
"n", -- normal mode map
"<leader>rv",
":lua require('refactoring').debug.print_var({ normal = true })<CR>",
{ noremap = true }
)Apologies for the long comment - I'm not sure if everything I said quite made sense, let me know if you have any questions and I can clarify. |
|
To follow up, I've opened #323 to show what a docs update would look like to clear up the discrepancy for the end user. Take a look and let me know what you think! |
|
@pranavrao145 Thanks for taking a look at this. Agreed this isn't optimal, let me edit this PR to go the config route where we default visual, but can optionally attempt to find var under cursor in normal mode. I'll comment again once ready for re-review. I'll take a peek at your doc update as well. |
…iterate on print_var_norm" This reverts commit f5f00dd.
|
@pranavrao145 Updated PR with implementing it another way. Lmk if you would like me to do it another way you mentioned, here I just set it as a config on the plugin itself so users can globally turn it on and off depending if they want to opt into it. |
|
@teddylear so I'm thinking about this a bit more, and there are two issues that I'm seeing arise:
Example map would be (with the vim.keymap.set(
"n", -- normal mode map
"<leader>rv",
":lua require('refactoring').debug.print_var({ normal = true })<CR>",
{ noremap = true }
)That way, the user can make two separate maps like this, still using both modes whenever they want instead of choosing one for always: vim.keymap.set(
"n", -- normal mode map
"<leader>rv",
":lua require('refactoring').debug.print_var({ normal = true })<CR>",
{ noremap = true }
)
vim.keymap.set(
"v", -- visual mode map
"<leader>rv",
":lua require('refactoring').debug.print_var({ normal = false })<CR>",
{ noremap = true }
)I think doing it this way, passing in the
vim.keymap.set(
"n", -- normal mode map
"<leader>rv",
":lua require('refactoring').debug.print_var()<CR>",
{ noremap = true }
)
vim.keymap.set(
"v", -- visual mode map
"<leader>rv",
":lua require('refactoring').debug.print_var()<CR>",
{ noremap = true }
)This works, and the plugin already is able to pick up which mode we're in and do whatever the user wants. If they're in normal mode, it automatically finds the var, and if it's visual, it automatically prints the selection. With the current behavior of the plugin, the user can already use whichever mode they want by default, and always switch to the other one if they're unhappy (even using the same map). So what I'm wondering is if we even need to make any changes to this at all. If we put in the There was some confusion in the commit history due to reverts and whatnot, as well as a lag in docs (my fault), so I think we may have confused ourselves and the end user (in that, the behaviour #321 asks for already existed when it was opened). Anyways, take a look and let me know how you want to move forward on this. |
|
@pranavrao145 I still think we need the change you mentioned in your last message because of this piece of code here. This means if we go from visual mode once and highlight something, then when going back to normal mode the |
|
@pranavrao145 Ok updated PR, please let me know what you think. For testing I'm using the following key binds map(
"v",
"<Leader>dv",
":lua require('refactoring').debug.print_var()<CR>",
{
noremap = true,
silent = true,
expr = false,
desc = "Refactoring plugin debug print var",
}
)
map(
"n",
"<Leader>dn",
":lua require('refactoring').debug.print_var({ normal = true })<CR>",
{
noremap = true,
silent = true,
expr = false,
desc = "Refactoring plugin debug print var",
}
)
|
Ohh okay fair enough, I failed to understand the problem - sorry about that. Thanks for the explanation and the PR changes, let me take a look again and I'll let you know. |
pranavrao145
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
feat: Split print_var and print_var_norm behaviors so we can iterate on print_var_norm
As discussed in #321 and from other issues/PRs raised, we can have a normal mode
print_varfunction (in this caseprint_var_norm) to get variable under cursor in normal mode while leaving the oldprint_varthat uses visual mode in place.@pranavrao145 Let me know if you want go this route (I'm alright to scrap this if we want to do something else). I figured this way we have the normal print var people have been asking for and can iterate on that, while still having the visual mode option. For not it's just a copy paste with one func difference, we can clean up the internals later but have these difference exposed interfaces. This way we have a fallback but give users what they want as well.
Also please double check my doc changes. I think I updated the required places, but I want to make this clear to end users.