(&self, line: &str)
| 100 | } |
| 101 | |
| 102 | fn complete_opt(&self, line: &str) -> Option<(usize, Vec<String>)> { |
| 103 | let (startpos, words) = split_idents_on_dot(line)?; |
| 104 | |
| 105 | let (word_start, iter) = self.get_available_completions(&words)?; |
| 106 | |
| 107 | let all_completions = iter |
| 108 | .filter(|res| { |
| 109 | res.as_ref() |
| 110 | .ok() |
| 111 | .is_none_or(|s| s.as_bytes().starts_with(word_start.as_bytes())) |
| 112 | }) |
| 113 | .collect::<Result<Vec<_>, _>>() |
| 114 | .ok()?; |
| 115 | let mut completions = if word_start.starts_with('_') { |
| 116 | // if they're already looking for something starting with a '_', just give |
| 117 | // them all the completions |
| 118 | all_completions |
| 119 | } else { |
| 120 | // only the completions that don't start with a '_' |
| 121 | let no_underscore = all_completions |
| 122 | .iter() |
| 123 | .filter(|&s| !s.as_bytes().starts_with(b"_")) |
| 124 | .cloned() |
| 125 | .collect::<Vec<_>>(); |
| 126 | |
| 127 | // if there are only completions that start with a '_', give them all of the |
| 128 | // completions, otherwise only the ones that don't start with '_' |
| 129 | if no_underscore.is_empty() { |
| 130 | all_completions |
| 131 | } else { |
| 132 | no_underscore |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | // sort the completions alphabetically |
| 137 | completions.sort_by(|a, b| a.as_wtf8().cmp(b.as_wtf8())); |
| 138 | |
| 139 | Some(( |
| 140 | startpos, |
| 141 | completions |
| 142 | .into_iter() |
| 143 | .map(|s| s.expect_str().to_owned()) |
| 144 | .collect(), |
| 145 | )) |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | cfg_if::cfg_if! { |
nothing calls this directly
no test coverage detected