mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-04 07:21:14 -03:00
Fix completely broken __fish_describe_command integration
Command completion descriptions were not being generated from `apropos`. Well, they were being generated but that was not being correctly used by fish core. Not sure when this was broken, but there's a possibility it was during the rust port. In addition to simply not working, it seems the old code tried to avoid allocations but String::split_at_mut() allocates a new string (since one allocation from the global allocator can't be split into two allocations to be freed separately). Use `String::as_mut_utfstr()` before splitting the &wstr instead of splitting the &str to actually do this alloc-free.
This commit is contained in:
@@ -1006,26 +1006,24 @@ fn complete_cmd_desc(&mut self, s: &wstr) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the key. This is the stuff after the command.
|
// Make the set components. This is the stuff after the command.
|
||||||
// For example:
|
// For example:
|
||||||
// elstr = lsmod
|
// elstr = lsmod\ta description
|
||||||
// cmd = ls
|
// cmd = ls
|
||||||
// key = mod
|
// key = mod
|
||||||
|
// val = A description
|
||||||
// Note an empty key is common and natural, if 'cmd' were already valid.
|
// Note an empty key is common and natural, if 'cmd' were already valid.
|
||||||
let (key, val) = elstr.split_at_mut(cmd.len());
|
let parts = elstr.as_mut_utfstr().split_at_mut(tab_idx);
|
||||||
let val = &mut val[1..];
|
let key = &parts.0[cmd.len()..tab_idx];
|
||||||
assert!(
|
let (_, val) = parts.1.split_at_mut(1);
|
||||||
!val.is_empty(),
|
|
||||||
"tab index should not have been at the end."
|
|
||||||
);
|
|
||||||
|
|
||||||
// And once again I make sure the first character is uppercased because I like it that
|
// And once again I make sure the first character is uppercased because I like it that
|
||||||
// way, and I get to decide these things.
|
// way, and I get to decide these things.
|
||||||
let mut upper_chars = val.as_char_slice()[0].to_uppercase();
|
let mut upper_chars = val.chars().next().unwrap().to_uppercase();
|
||||||
if let (Some(c), None) = (upper_chars.next(), upper_chars.next()) {
|
if let (Some(c), None) = (upper_chars.next(), upper_chars.next()) {
|
||||||
val.as_char_slice_mut()[0] = c;
|
val.as_char_slice_mut()[0] = c;
|
||||||
}
|
}
|
||||||
lookup.insert(&*key, &*val);
|
lookup.insert(key, &*val);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then do a lookup on every completion and if a match is found, change to the new
|
// Then do a lookup on every completion and if a match is found, change to the new
|
||||||
|
|||||||
Reference in New Issue
Block a user