@@ -46,9 +46,9 @@ pub(crate) fn auto_import(ctx: AssistCtx) -> Option<Assist> {
4646
4747 let name_ref_to_import =
4848 path_under_caret. syntax ( ) . descendants ( ) . find_map ( ast:: NameRef :: cast) ?;
49- if dbg ! ( source_analyzer
50- . resolve_path( ctx. db, & name_ref_to_import. syntax( ) . ancestors( ) . find_map( ast:: Path :: cast) ?) )
51- . is_some ( )
49+ if source_analyzer
50+ . resolve_path ( ctx. db , & name_ref_to_import. syntax ( ) . ancestors ( ) . find_map ( ast:: Path :: cast) ?)
51+ . is_some ( )
5252 {
5353 return None ;
5454 }
@@ -307,4 +307,117 @@ mod tests {
307307 " ,
308308 ) ;
309309 }
310+
311+ #[ test]
312+ fn associated_struct_function ( ) {
313+ check_assist (
314+ auto_import,
315+ r"
316+ mod test_mod {
317+ pub struct TestStruct {}
318+ impl TestStruct {
319+ pub fn test_function() {}
320+ }
321+ }
322+
323+ fn main() {
324+ TestStruct::test_function<|>
325+ }
326+ " ,
327+ r"
328+ use test_mod::TestStruct;
329+
330+ mod test_mod {
331+ pub struct TestStruct {}
332+ impl TestStruct {
333+ pub fn test_function() {}
334+ }
335+ }
336+
337+ fn main() {
338+ TestStruct::test_function<|>
339+ }
340+ " ,
341+ ) ;
342+ }
343+
344+ #[ test]
345+ fn associated_trait_function ( ) {
346+ check_assist (
347+ auto_import,
348+ r"
349+ mod test_mod {
350+ pub trait TestTrait {
351+ fn test_function();
352+ }
353+ pub struct TestStruct {}
354+ impl TestTrait for TestStruct {
355+ fn test_function() {}
356+ }
357+ }
358+
359+ fn main() {
360+ test_mod::TestStruct::test_function<|>
361+ }
362+ " ,
363+ r"
364+ use test_mod::TestTrait;
365+
366+ mod test_mod {
367+ pub trait TestTrait {
368+ fn test_function();
369+ }
370+ pub struct TestStruct {}
371+ impl TestTrait for TestStruct {
372+ fn test_function() {}
373+ }
374+ }
375+
376+ fn main() {
377+ test_mod::TestStruct::test_function<|>
378+ }
379+ " ,
380+ ) ;
381+ }
382+
383+ #[ test]
384+ fn trait_method ( ) {
385+ check_assist (
386+ auto_import,
387+ r"
388+ mod test_mod {
389+ pub trait TestTrait {
390+ fn test_method(&self);
391+ }
392+ pub struct TestStruct {}
393+ impl TestTrait for TestStruct {
394+ fn test_method(&self) {}
395+ }
396+ }
397+
398+ fn main() {
399+ let test_struct = test_mod::TestStruct {};
400+ test_struct.test_method<|>
401+ }
402+ " ,
403+ r"
404+ use test_mod::TestTrait;
405+
406+ mod test_mod {
407+ pub trait TestTrait {
408+ fn test_method(&self);
409+ }
410+ pub struct TestStruct {}
411+ impl TestTrait for TestStruct {
412+ fn test_method(&self) {}
413+ }
414+ }
415+
416+ fn main() {
417+ let test_struct = test_mod::TestStruct {};
418+ test_struct.test_method<|>
419+ }
420+ " ,
421+ ) ;
422+ }
310423}
0 commit comments