-
Notifications
You must be signed in to change notification settings - Fork 157
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
Don't slice line in DefaultCompleter #695
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #695 +/- ##
==========================================
+ Coverage 49.26% 56.09% +6.83%
==========================================
Files 46 46
Lines 7911 7993 +82
==========================================
+ Hits 3897 4484 +587
+ Misses 4014 3509 -505
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goes towards fixing nushell/nushell#8091. nushell/nushell#11488 (which should finish the job) relies on this PR to make
only_buffer_difference: true
work with the columnar and list menus.I don't know what exactly the old behavior was supposed to be (I looked at the history of the relevant files but couldn't find any recent commits that seemed to change behavior), so maybe this PR has different behavior for the user (it also changes the contract of
Completer::complete
). But I think I've narrowed down the issue, so someone else can at least make a new PR based on that.It seems like the problem was in
DefaultCompleter::complete
, where it doesline[0..pos]
:reedline/src/completion/default.rs
Lines 71 to 75 in f396223
DefaultCompleter::complete
assumes that the line given to it is the whole line and thatpos
is the cursor position. It also assumes that the content to complete begins at the start of the line and ends atpos
. However, withonly_buffer_difference
set to true, the line passed to the completer is only the changed portion of the buffer, and the argument topos
is the start of the changed portion of the buffer rather than the cursor position. So when you typecd <TAB>c
,line
is"c"
andpos
is3
, soline[0..pos]
fails.Although there's a check for the line being empty, there isn't one for
pos
being out of bounds. I figured it'd be easier to have the menus slice the line before sending it over to be completed so they can decide which portion of the text to complete.pos
would then be used solely to determine the spans of the returnedSuggestion
s.One problem is that although the
DefaultCompleter
assumes that the argument topos
is the end of the content to complete, as far as I can tell,HistoryCompleter
seems to assume thatpos
is the start of the content's span (edit: I've now changed it to use the end instead of the start, for consistency):reedline/src/completion/history.rs
Lines 53 to 57 in f396223
On the one hand, making
pos
the start is nice because you add the input's length to get the end. On the other hand, makingpos
the end is nice because that's the cursor position (unless you haveonly_buffer_difference
set to true). Either way, the doc comment onCompleter::complete
doesn't seem detailed enough (edit: I've now changed it to say thatpos
must be the end of the text):reedline/src/completion/base.rs
Lines 29 to 31 in f396223
(these permalink snippet things are so cool)
I guess it doesn't really matter because the
HistoryCompleter
isn't used the same way as theDefaultCompleter
, but it'd still be nice to have consistency.Here's a recording of the changes using the columnar menu and
only_buffer_difference
set to true:and with the list menu:
There was also a small bug in
string_difference
where, if the old buffer was of lengthn
and the new buffer was longer than that (sayn+1
),old_buffer[0..n] == new_buffer[0..n]
, andold_buffer[n] == new_buffer[n+1]
, then no difference would be detected. That seems to be fixed now (added one test).