Skip to content

Commit 659aa89

Browse files
committed
[function-grep]
While thinking about filter in gui, I realized it might make sense to have filter for just one language for efficiancy and in case a filter with similiar attributes doesn't work if you pick just a single language
1 parent 7f554f6 commit 659aa89

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

function-grep/src/filter.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,25 @@ pub type InstantiatedFilterType =
227227
pub enum SingleOrMany<A: Info<Supported = All>, M: Info<Supported = Language>> {
228228
All(A),
229229
Many(Many<M>),
230+
Single(M),
230231
}
231232
impl<A: Info<Supported = All>, M: Info<Supported = Language>> SingleOrMany<A, M> {
232233
#[must_use]
233234
pub fn filter_name(&self) -> String {
234235
match self {
235236
Self::All(f) => f.filter_name(),
236237
Self::Many(many) => many.name.clone(),
238+
Self::Single(s) => s.filter_name(),
237239
}
238240
}
239241

240242
#[must_use]
241243
pub fn supports(&self) -> SupportedLanguages {
242244
match self {
245+
// Self::Single(s) => SupportedLanguages::Single(s.)
243246
Self::All(_) => SupportedLanguages::All,
244247
Self::Many(many) => SupportedLanguages::Many(many.filters.keys().cloned().collect()),
248+
SingleOrMany::Single(_) => todo!(),
245249
}
246250
}
247251
}
@@ -251,9 +255,17 @@ impl<A: Info<Supported = All>, M: Info<Supported = Language>> Display for Single
251255
}
252256
}
253257
impl<'a> FilterType<'a> {
258+
pub fn specific(&self, s: &str) -> Option<Self> {
259+
match self {
260+
Self::All(_) | Self::Single(_) => None,
261+
Self::Many(m) => m.filters.get(s).map(|x| Self::Single(*x)),
262+
}
263+
}
264+
254265
pub fn to_filter(&self, s: &str) -> Result<InstantiatedFilterType, String> {
255266
match self {
256267
SingleOrMany::All(a) => a.to_filter(s).map(SingleOrMany::All),
268+
SingleOrMany::Single(a) => a.to_filter(s).map(SingleOrMany::Single),
257269
SingleOrMany::Many(Many { name, filters }) => filters
258270
.iter()
259271
.map(|(name, f)| f.to_filter(s).map(|f| (name.clone(), f)))
@@ -345,6 +357,13 @@ impl<'a> Filters<'a> {
345357
match filters {
346358
SingleOrMany::All(_) => Err("cannot add to an all filter".to_string()),
347359
SingleOrMany::Many(Many { filters, .. }) => merge_filters(filters, filter),
360+
SingleOrMany::Single(s) => {
361+
*filters = SingleOrMany::Many(Many {
362+
name: "".to_string(),
363+
filters: HashMap::from([(s.filter_name(), *s)]),
364+
});
365+
Ok(())
366+
}
348367
}
349368
} else {
350369
self.filters.insert(name, filter);

function-grep/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ impl ParsedFile {
149149
filter.and_then(|f| self.filter_inner(f))
150150
}
151151
InstantiatedFilterType::All(f) => self.filter_inner(f),
152+
InstantiatedFilterType::Single(f) => self.filter_inner(f),
152153
}
153154
}
154155

0 commit comments

Comments
 (0)