Improve fuzzy matching
While doing fuzzy matching on an optional `extension_sql!` declared
type, the schema generator will look for `core::option::Option<Foo>`
while the `SqlDeclared` will store `Option<Foo>`. This commit alters
the fuzzy matcher to search for both types so that such types can be
used.
@@ -194,7 +194,7 @@ impl SqlDeclaredEntity {
(SqlDeclared::Type(identifier_name), &SqlDeclaredEntity::Type(data))
| (SqlDeclared::Enum(identifier_name), &SqlDeclaredEntity::Enum(data))
| (SqlDeclared::Function(identifier_name), &SqlDeclaredEntity::Function(data)) => {
- identifier_name == &data.name
+ let matches = |identifier_name: &str| identifier_name == &data.name
|| identifier_name == &data.option
|| identifier_name == &data.vec
|| identifier_name == &data.vec_option
@@ -202,8 +202,22 @@ impl SqlDeclaredEntity {
|| identifier_name == &data.option_vec_option
|| identifier_name == &data.array
|| identifier_name == &data.option_array
- || identifier_name == &data.varlena
- || data.pg_box.contains(&identifier_name)
+ || identifier_name == &data.varlena;
+ if matches(&*identifier_name) || data.pg_box.contains(&identifier_name) {
+ return true
+ }
+ // there are cases where the identifier is
+ // `core::option::Option<Foo>` while the data stores
+ // `Option<Foo>` check again for this
+ let generics_start = match identifier_name.find('<') {
+ None => return false,
+ Some(idx) => idx,
+ };
+ let qualification_end = match identifier_name[..generics_start].rfind("::") {
+ None => return false,
+ Some(idx) => idx,
+ };
+ matches(&identifier_name[qualification_end+2..])
}
_ => false,
}
