mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
Fix slice indexing (#6322)
* Return empty suggestions if no span contents is present * Fix slice indexing
This commit is contained in:
parent
1d18f6947e
commit
4ab468e65f
2 changed files with 11 additions and 3 deletions
|
@ -81,6 +81,9 @@ impl CommandCompletion {
|
|||
match_algorithm: MatchAlgorithm,
|
||||
) -> Vec<Suggestion> {
|
||||
let partial = working_set.get_span_contents(span);
|
||||
if partial.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
let filter_predicate = |command: &[u8]| match_algorithm.matches_u8(command, partial);
|
||||
|
||||
|
|
|
@ -576,8 +576,7 @@ impl EngineState {
|
|||
return &contents[(span.start - start)..(span.end - start)];
|
||||
}
|
||||
}
|
||||
|
||||
panic!("internal error: span missing in file contents cache")
|
||||
&[0u8; 0]
|
||||
}
|
||||
|
||||
pub fn get_config(&self) -> &Config {
|
||||
|
@ -1292,7 +1291,13 @@ impl<'a> StateWorkingSet<'a> {
|
|||
if permanent_end <= span.start {
|
||||
for (contents, start, finish) in &self.delta.file_contents {
|
||||
if (span.start >= *start) && (span.end <= *finish) {
|
||||
return &contents[(span.start - start)..(span.end - start)];
|
||||
let begin = span.start - start;
|
||||
let mut end = span.end - start;
|
||||
if begin > end {
|
||||
end = *finish - permanent_end;
|
||||
}
|
||||
|
||||
return &contents[begin..end];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue