mirror of
https://github.com/nushell/nushell.git
synced 2025-04-24 13:18:18 +02:00
refactor: naming, doc comment
This commit is contained in:
parent
9e60767fc6
commit
7e0cdc8058
@ -49,14 +49,15 @@ fn command_name_span_from_call_head(
|
|||||||
let head_content = working_set.get_span_contents(head_span);
|
let head_content = working_set.get_span_contents(head_span);
|
||||||
let mut head_words = head_content.split(|c| *c == b' ').collect::<Vec<_>>();
|
let mut head_words = head_content.split(|c| *c == b' ').collect::<Vec<_>>();
|
||||||
let mut name_words = name.split(' ').collect::<Vec<_>>();
|
let mut name_words = name.split(' ').collect::<Vec<_>>();
|
||||||
let mut matched_len = 0;
|
let mut matched_len = name_words.len() - 1;
|
||||||
while let Some(word) = name_words.pop() {
|
while let Some(name_word) = name_words.pop() {
|
||||||
while let Some(head_word) = head_words.pop() {
|
while let Some(head_word) = head_words.pop() {
|
||||||
if head_word.is_empty() && !word.is_empty() {
|
// for extra spaces, like those in the `command name` example
|
||||||
|
if head_word.is_empty() && !name_word.is_empty() {
|
||||||
matched_len += 1;
|
matched_len += 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if word.as_bytes() == head_word {
|
if name_word.as_bytes() == head_word {
|
||||||
matched_len += head_word.len();
|
matched_len += head_word.len();
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@ -68,9 +69,6 @@ fn command_name_span_from_call_head(
|
|||||||
if name_words.len() > head_words.len() {
|
if name_words.len() > head_words.len() {
|
||||||
return head_span;
|
return head_span;
|
||||||
}
|
}
|
||||||
if !name_words.is_empty() {
|
|
||||||
matched_len += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Span::new(head_span.end.saturating_sub(matched_len), head_span.end)
|
Span::new(head_span.end.saturating_sub(matched_len), head_span.end)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user