-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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: panic on completion for an alias (#12090) #12596
base: main
Are you sure you want to change the base?
Conversation
you could probably save a few lines by changing it from // we'll check if start of span is greater than offset, to prevent panic
// else we can use the start and end values from last and use that.
if last.0.start >= offset {
self.complete_commands(
working_set,
Span::new(last.0.start, pos),
offset,
false,
options.match_algorithm,
)
} else {
self.complete_commands(
working_set,
Span::new(last.0.start, last.0.end),
offset,
false,
options.match_algorithm,
)
} to something like this // we'll check if start of span is greater than offset, to prevent panic
// else we can use the start and end values from last and use that.
let end = if last.0.start >= offset {
pos
} else {
last.0.end
};
self.complete_commands(
working_set,
Span::new(last.0.start, end),
offset,
false,
options.match_algorithm,
) i dont know all the details about the bug you are fixing with this, but could this also be solved by changing the offset instead of the last span? because the span is probably not broken when its calculated, so i would not change it (might break stuff somewhere else) but as i said i dont know the full problem here, so i might be wrong |
you might be able to just this here let offset = offset.min(last.0.start).min(last.0.end); let mut results = working_set
.find_commands_by_predicate(filter_predicate, true)
.into_iter()
.map(move |x| SemanticSuggestion {
suggestion: Suggestion {
value: String::from_utf8_lossy(&x.0).to_string(),
description: x.1,
style: None,
extra: None,
span: reedline::Span::new(span.start - offset, span.end - offset), // offset is smaller or equal to span.end and span.start
append_whitespace: true,
},
kind: Some(SuggestionKind::Command(x.2)),
})
.collect::<Vec<_>>(); |
OK I'll check this but is there a way to log from which character to which character the span is calculated for? I can see the character number but not sure how to log the character? This is just to confirm if the span has been calculated correctly or not |
Would it be possible to add a test for it? We already have some tests for completions. |
Ok But can you guide me on how to add a test cases where I've to create an alias and then call suggestions. |
I haven't worked on completions myself, so I can't provide a concrete advice, but you can look at |
This PR Fixes: #12090
Description
This pr added a if check if offset during completion is smaller than the span value, this prevents panics during subtraction when passing value to the
reedline
User-Facing Changes
Tests + Formatting
After Submitting