-
-
Notifications
You must be signed in to change notification settings - Fork 8
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: replace current match #14
base: main
Are you sure you want to change the base?
feat: replace current match #14
Conversation
… match changes - add keymaps for moving between matches
Hmm, yes, this appears be a larger PR than I expected… I don't mind refactorings, but they should be a separate PR for clarity reasons. I think it might sense to split up this feature into separate PRs maybe? Like one big PR for all the refactoring you need in preparation for the feature, and then another PR for the feature itself. That way, you can get changes already in, and it would also be easier to review the PR Another way to split this up to smaller sizes is to disregard ranges at first, and only implement "replace current match" for substitutions on the whole file. And add in ranges later – I assume ranges are one of the things that complicate this feature quite a bit. |
Perhaps that wasn't clear, but I did not do any optional refactoring, yet.
Sorry but I have no idea what you mean by this or how that could be done. It sounds to me like you are mainly perturbed by the amount of changes? I can't think of a way to split this that would make any sense. Do you have a way of splitting this in mind? |
I mean we could probably do the changes to how matches are stored and then used later in a separate PR, |
So, the current PR changes a total of ~600 lines. Considering that the whole repo is only barely larger, this is unreasonably large. Looking into it, it appears that the PR has various types of changes:
To distinguish 3 and 4, you could think about how far you can make "prepratory" changes without actually adding in the new feature. Also, your PR is based on an outdated version of the repo, which results in stuff like the regex101 config missing in your fork. You should sync up your fork. Like all these changes are not sufficient for the PR to be merged, but only for the PR to be in a state where it can be properly reviewed. |
I understand this needs to be cleaned up and is not ready for review. Like I said, I wanted to synch with you on the direction before I continue. Sorry if this is not standard procedure.
|
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.
Just some minor things I noticed while going through the code
lua/rip-substitute/rg-operations.lua
Outdated
@@ -1,12 +1,33 @@ | |||
local M = {} | |||
local config = require("rip-substitute.config").config |
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.
config
should not be called at the top of the file, since it's then only set once. This prevents the user from running .setup
again to change a config. Thus, config
should always be set dynamically inside a function
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.
I was wondering about that. For some reason I feel kinda dirty requiring it on every execution of a function.
Is there any drawback to the way you're suggesting?
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.
No, since lua caches it anyway, there is no real drawback. Yeah, it feels a bit weird, since in most other languages, imports should always be placed at the top of the file. But in lua, it's often the better practice to require
inside functions for various reasons (lazy evaluation being the other important one). Bit counterintuitive, but you get used to it.
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.
Ok great. That's an obvious choice then.
nvim-float.log
Outdated
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.
leftover file
tbh, I am also not really familiar what the "standard procedure" is. Nonetheless, even just giving some feedback on the ongoing direction is hard, if there is so much noise in the PR, so the cleanup would be needed regardless
Yes, and due to 600+ lines of diff, it was not easy to tell whether this is a one-time occurrence or something that happens multiple times. ;)
Not sure what exactly you did, but before, the diff had a lot of cases where it split up one line into multiple lines, indicating that some formatter with lower line length was used. Anyway, I use stylua with the config provided in the repo. If you simply run stylua in the repo root, it should by default pick up the config by itself. The diff looks okay now. Sorry, if I am came off as nitpicky or something, imho keeping noise to a minimum is essential in large PRs, as it's otherwise hard to assess what actual changes have been made. And even if this is a draft PR and therefore still WIP, a large PR with a lot of noise makes it harder to understand what's going on and thus also hard to even give intermediary feedback. In hindsight, most of the issue was due to the formatting issues, but that 1. was less of an issue was in itself hard to tell with so much noise going on there.
Well, you do a lot of refactorings which make sense, but can be split off into its own PR. And keeping PRs as small is possible is usually desirable (better readability, thus easier reviewability, also cleaner git history).
By moving these into a separate PR, the remaining changes in
Nice, that's actually a good use case for |
regarding the remaining issues:
I think this is not the case anymore with your latest changes.
That's probably just an off-by-one issue somewhere since some nvim functions expect columns are zero-based and some expect them to be one-based.
Currently (without your PR), regarding the general direction: Will have an in-depth look once the remaining issues are resolved, but I think the general direction is otherwise fine. Separating your feature into mostly a new module makes sense |
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.
a bunch of more comments, some minor things I noticed, but also some more important stuff like on the keymaps.
lua/rip-substitute/config.lua
Outdated
@@ -20,14 +20,23 @@ local defaultConfig = { | |||
keymaps = { | |||
-- normal & visual mode | |||
confirm = "<CR>", | |||
confirmAll = "<S-CR>", |
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.
for the sake of not introducing a breaking change for existing users, the current keymaps behavior should not be changed.
confirm
should be used to confirm all like it's doing now, and your feature should introduce a confirmSingle
which uses a new keymaps <S-CR>
. Yes, it's not ergonomic, but otherwise your PR creates a breaking change which will irritate users.
local msg = | ||
"`incrementalPreview.hlGroups.{name}` is deprecated, use `incrementalPreview.matchHlGroup` instead." | ||
notify(msg, "warn") | ||
-- local msg = |
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.
as annoying as it is, I'm afraid we will need a deprecation notice for the now basically reverted setting…
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.
just to make sure I understand correctly:
the new deprecation notice would be:
"incrementalPreview.matchHlGroup
is deprecated, use incrementalPreview.hlGroups.{name}
instead."
?
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.
yep
lua/rip-substitute/matches.lua
Outdated
end | ||
end | ||
|
||
function M.selectPrevMatch() |
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.
selectPrevMatch and selectNextMatch could be merged into one function taking the direction as a parameter
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.
are you ok with keeping shorthand functions like this:
---@param direction "next" | "prev"
local function cycleMatches(direction)
...
function M.selectNextMatch()
cycleMatches("next")
end
function M.selectPrevMatch()
cycleMatches("prev")
end
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.
why even the wrapper functions? You can just assign cycleMatches
to the keymap definitions for the popup win?
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.
perhaps I'm ignorant here...
As far as I'm aware the only way to do that would be with an inline function since vim.keymap.set
doesn't have a mechanism to pass extra args to the callback function.
So If i have to write function()...end, I might as well do it like this instead of the inline function.
That was my thinking process anyway
) | ||
end | ||
state.selectedMatch = state.matches[newSelectedMatchIndex] | ||
--TODO: this will probably clear too many highlights |
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.
yes, an issue will be multiple matches in one line, for instance. Not totally sure what would be the best solution here though
lua/rip-substitute/rg-operations.lua
Outdated
---@param selected boolean | ||
---@param targetBuf number | ||
---@param incPreviewNs number | ||
function M.highlightReplacement(match, selected, targetBuf, incPreviewNs) |
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.
targetBuf
and incPreviewNs
do not need to be passed, since they can be accessed via state
.
lua/rip-substitute/rg-operations.lua
Outdated
---@param targetBuf number | ||
---@param incPreviewNs number |
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.
targetBuf
and incPreviewNs
do not need to be passed, since they can be accessed via state
.
Wow. That's a lot to take in 😄 I think I have a better idea of what you are looking for now. I agree with all the remarks and will try to adapt the PR accordingly.
All good 👍 To be honest I was getting a bit into my feelings because of some of the critique, but that might just be me. I'm a sucker for words of affirmation 😄
completely fair. I guess I got too excited and pushed too early. |
- utils.map -> vim.tbl_map - no more pcall - renamed some functions/options to have less breaking changes - remove useless --vimgrep - use vim.o.scrolloff instead of magic number for padding - some minor refactoring
Ok I think I took all your remarks into account and made adaptations accordingly. |
Checklist
README.md
(the.txt
file is auto-generated and does not need to be modified).This is just a rough first draft. There's TODOs and bugs still, but I would like to get some feedback at this point to make sure I'm going in a direction that aligns with the project. I tried my best to stick with your naming scheme etc..
I was itching to do some more refactoring, but I want to be respectful to your project. Maybe we can discuss that at some point.
I have not yet adapted the readme, because I wanted to make sure the suggested changes are ok with you.
added functionality:
known issues: