Reuse recorded syntext path/regex selection, then parse only matching files and explicit declaration/import context. No working-copy index use.
(
&self,
mut set: SourceSet,
targets: &[Symbol],
parser: &mut ParserRegistry,
)
| 201 | /// Reuse recorded syntext path/regex selection, then parse only matching |
| 202 | /// files and explicit declaration/import context. No working-copy index use. |
| 203 | pub fn select_context( |
| 204 | &self, |
| 205 | mut set: SourceSet, |
| 206 | targets: &[Symbol], |
| 207 | parser: &mut ParserRegistry, |
| 208 | ) -> Result<SourceSet, RepositoryError> { |
| 209 | if targets.is_empty() { |
| 210 | return Ok(set); |
| 211 | } |
| 212 | let mut known: BTreeSet<_> = set.files.iter().map(|file| file.path.clone()).collect(); |
| 213 | let patterns = targets |
| 214 | .iter() |
| 215 | .map(|symbol| { |
| 216 | let name = regex::escape(&symbol.entity.name); |
| 217 | let pattern = if let Some(owner) = &symbol.owner { |
| 218 | let owner = regex::escape(owner); |
| 219 | format!(r"(?s:\b{owner}\b.*\b{name}\b|\b{name}\b.*\b{owner}\b)") |
| 220 | } else { |
| 221 | format!(r"\b{name}\b") |
| 222 | }; |
| 223 | regex::bytes::Regex::new(&pattern).map(|pattern| (symbol, pattern)) |
| 224 | }) |
| 225 | .collect::<Result<Vec<_>, _>>() |
| 226 | .map_err(|error| RepositoryError::InvalidOperation { |
| 227 | message: error.to_string(), |
| 228 | })?; |
| 229 | let pattern = patterns |
| 230 | .iter() |
| 231 | .map(|(_, pattern)| pattern.as_str()) |
| 232 | .collect::<BTreeSet<_>>() |
| 233 | .into_iter() |
| 234 | .collect::<Vec<_>>() |
| 235 | .join("|"); |
| 236 | let plan = RecordedContentSearch::new( |
| 237 | self.files |
| 238 | .keys() |
| 239 | .filter(|path| { |
| 240 | !known.contains(*path) |
| 241 | && targets.iter().any(|target| candidate_path(path, target)) |
| 242 | }) |
| 243 | .map(String::as_str), |
| 244 | &pattern, |
| 245 | ContentSearchOptions::default(), |
| 246 | ) |
| 247 | .map_err(|error| RepositoryError::InvalidOperation { |
| 248 | message: error.to_string(), |
| 249 | })?; |
| 250 | let mut failed = 0; |
| 251 | let matches = plan.matching_sources( |
| 252 | 256usize.saturating_sub(set.files.len()), |
| 253 | 8 * 1024 * 1024, |
| 254 | |path| match self.content(path) { |
| 255 | Ok(content) => Ok::<_, RepositoryError>(content), |
| 256 | Err(_) => { |
| 257 | failed += 1; |
| 258 | Ok(None) |
| 259 | } |
| 260 | }, |
no test coverage detected