Skip to content

Commit 7f554f6

Browse files
committed
[function-grep] type alias for attributes
1 parent 0f2d0b0 commit 7f554f6

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

function-grep/src/filter.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ impl fmt::Display for Attribute {
3535
write!(f, "{}", self.0)
3636
}
3737
}
38-
38+
// TODO: should we have way to specify an attribute as being optional
39+
pub type Attributes = HashMap<Attribute, AttributeType>;
3940
use crate::SupportedLanguages;
4041
pub trait Filter: HasFilterInformation {
4142
fn parse_filter(&self, s: &str) -> Result<FilterFunction, String>;
@@ -59,7 +60,7 @@ pub struct FilterInformation<Supports> {
5960
/// what languages this filter works on
6061
supported_languages: Supports,
6162

62-
attributes: HashMap<Attribute, AttributeType>,
63+
attributes: Attributes,
6364
}
6465

6566
impl<Supports> fmt::Display for FilterInformation<Supports> {
@@ -90,7 +91,7 @@ impl<Supports> FilterInformation<Supports> {
9091
}
9192

9293
#[must_use]
93-
pub const fn attributes(&self) -> &HashMap<Attribute, AttributeType> {
94+
pub const fn attributes(&self) -> &Attributes {
9495
&self.attributes
9596
}
9697

@@ -112,7 +113,7 @@ pub trait HasFilterInformation {
112113
fn description(&self) -> String;
113114
/// what languages this filter works on
114115
fn supports(&self) -> Self::Supports;
115-
fn attributes(&self) -> HashMap<Attribute, AttributeType>;
116+
fn attributes(&self) -> Attributes;
116117
// TODO: have filter creation informaton about types and fields for uis
117118
fn filter_info(&self) -> FilterInformation<Self::Supports> {
118119
FilterInformation {
@@ -165,7 +166,7 @@ impl<Supports> InstantiatedFilter<Supports> {
165166
}
166167

167168
#[must_use]
168-
pub const fn attributes(&self) -> &HashMap<Attribute, AttributeType> {
169+
pub const fn attributes(&self) -> &Attributes {
169170
self.filter_information.attributes()
170171
}
171172

function-grep/src/filter/general_filters.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use tree_sitter::Node;
44

55
use super::{
66
filter_parsers::{extra, label, number},
7-
All, Attribute, AttributeType, Filter, FilterFunction, HasFilterInformation, Language,
7+
All, Attribute, AttributeType, Attributes, Filter, FilterFunction, HasFilterInformation,
8+
Language,
89
};
910

1011
pub struct FunctionInLines;
@@ -66,7 +67,7 @@ format:
6667
\tend: [number] start: [number]"
6768
.to_string()
6869
}
69-
fn attributes(&self) -> HashMap<Attribute, AttributeType> {
70+
fn attributes(&self) -> Attributes {
7071
HashMap::from([
7172
(Attribute("start".to_string()), AttributeType::Number),
7273
(Attribute("end".to_string()), AttributeType::Number),
@@ -106,7 +107,7 @@ impl HasFilterInformation for FunctionInImpl {
106107
Language("Rust".to_string())
107108
}
108109

109-
fn attributes(&self) -> HashMap<Attribute, AttributeType> {
110+
fn attributes(&self) -> Attributes {
110111
HashMap::new()
111112
}
112113
}
@@ -126,7 +127,7 @@ impl HasFilterInformation for FunctionWithParameterRust {
126127
Language("Rust".to_owned())
127128
}
128129

129-
fn attributes(&self) -> HashMap<Attribute, AttributeType> {
130+
fn attributes(&self) -> Attributes {
130131
HashMap::from([(Attribute("Name".to_string()), AttributeType::String)])
131132
}
132133

0 commit comments

Comments
 (0)