@@ -164,6 +164,22 @@ pub enum Definition {
164
164
NatspecParsingError ( Error ) ,
165
165
}
166
166
167
+ impl PartialEq for Definition {
168
+ fn eq ( & self , other : & Self ) -> bool {
169
+ match ( self , other) {
170
+ ( Self :: Constructor ( a) , Self :: Constructor ( b) ) => a. span . start == b. span . start ,
171
+ ( Self :: Enumeration ( a) , Self :: Enumeration ( b) ) => a. span . start == b. span . start ,
172
+ ( Self :: Error ( a) , Self :: Error ( b) ) => a. span . start == b. span . start ,
173
+ ( Self :: Event ( a) , Self :: Event ( b) ) => a. span . start == b. span . start ,
174
+ ( Self :: Function ( a) , Self :: Function ( b) ) => a. span . start == b. span . start ,
175
+ ( Self :: Modifier ( a) , Self :: Modifier ( b) ) => a. span . start == b. span . start ,
176
+ ( Self :: Struct ( a) , Self :: Struct ( b) ) => a. span . start == b. span . start ,
177
+ ( Self :: Variable ( a) , Self :: Variable ( b) ) => a. span . start == b. span . start ,
178
+ _ => false ,
179
+ }
180
+ }
181
+ }
182
+
167
183
impl Definition {
168
184
/// Validate a definition and generate [`Diagnostic`]s for errors
169
185
pub fn validate ( & self , options : & ValidationOptions ) -> ItemDiagnostics {
@@ -276,18 +292,39 @@ pub fn find_items(cursor: Cursor) -> Vec<Definition> {
276
292
VariableDeclaration :: query( ) ,
277
293
] ) {
278
294
let def = match m. query_number {
279
- 0 => ConstructorDefinition :: extract ( m) ,
280
- 1 => EnumDefinition :: extract ( m) ,
281
- 2 => ErrorDefinition :: extract ( m) ,
282
- 3 => EventDefinition :: extract ( m) ,
283
- 4 => FunctionDefinition :: extract ( m) ,
284
- 5 => ModifierDefinition :: extract ( m) ,
285
- 6 => StructDefinition :: extract ( m) ,
286
- 7 => VariableDeclaration :: extract ( m) ,
295
+ 0 => Some (
296
+ ConstructorDefinition :: extract ( m) . unwrap_or_else ( Definition :: NatspecParsingError ) ,
297
+ ) ,
298
+ 1 => Some ( EnumDefinition :: extract ( m) . unwrap_or_else ( Definition :: NatspecParsingError ) ) ,
299
+ 2 => Some ( ErrorDefinition :: extract ( m) . unwrap_or_else ( Definition :: NatspecParsingError ) ) ,
300
+ 3 => Some ( EventDefinition :: extract ( m) . unwrap_or_else ( Definition :: NatspecParsingError ) ) ,
301
+ 4 => {
302
+ let def =
303
+ FunctionDefinition :: extract ( m) . unwrap_or_else ( Definition :: NatspecParsingError ) ;
304
+ if out. contains ( & def) {
305
+ None
306
+ } else {
307
+ Some ( def)
308
+ }
309
+ }
310
+ 5 => {
311
+ let def =
312
+ ModifierDefinition :: extract ( m) . unwrap_or_else ( Definition :: NatspecParsingError ) ;
313
+ if out. contains ( & def) {
314
+ None
315
+ } else {
316
+ Some ( def)
317
+ }
318
+ }
319
+ 6 => Some ( StructDefinition :: extract ( m) . unwrap_or_else ( Definition :: NatspecParsingError ) ) ,
320
+ 7 => Some (
321
+ VariableDeclaration :: extract ( m) . unwrap_or_else ( Definition :: NatspecParsingError ) ,
322
+ ) ,
287
323
_ => unreachable ! ( ) ,
324
+ } ;
325
+ if let Some ( def) = def {
326
+ out. push ( def) ;
288
327
}
289
- . unwrap_or_else ( Definition :: NatspecParsingError ) ;
290
- out. push ( def) ;
291
328
}
292
329
out
293
330
}
0 commit comments