@@ -89,31 +89,38 @@ fn add_import(
8989 ctx : & AssistContext < ' _ > ,
9090 edit : & mut ide_db:: source_change:: SourceChangeBuilder ,
9191) {
92- // for `<i32 as std::ops::Add>`
93- let path_type =
94- qualifier. segment ( ) . unwrap ( ) . syntax ( ) . children ( ) . filter_map ( ast:: PathType :: cast) . last ( ) ;
95- let import = match path_type {
96- Some ( it) => it. path ( ) . unwrap ( ) ,
97- None => qualifier,
98- } ;
99-
100- // in case for `<_>`
101- if import. coloncolon_token ( ) . is_none ( ) {
102- return ;
103- }
92+ if let Some ( path_segment) = qualifier. segment ( ) {
93+ // for `<i32 as std::ops::Add>`
94+ let path_type = path_segment. syntax ( ) . children ( ) . filter_map ( ast:: PathType :: cast) . last ( ) ;
95+ let import = match path_type {
96+ Some ( it) => {
97+ if let Some ( path) = it. path ( ) {
98+ path
99+ } else {
100+ return ;
101+ }
102+ }
103+ None => qualifier,
104+ } ;
104105
105- let scope = ide_db :: imports :: insert_use :: ImportScope :: find_insert_use_container (
106- import. syntax ( ) ,
107- & ctx . sema ,
108- ) ;
106+ // in case for `<_>`
107+ if import. coloncolon_token ( ) . is_none ( ) {
108+ return ;
109+ }
109110
110- if let Some ( scope) = scope {
111- let scope = match scope {
112- ImportScope :: File ( it) => ImportScope :: File ( edit. make_mut ( it) ) ,
113- ImportScope :: Module ( it) => ImportScope :: Module ( edit. make_mut ( it) ) ,
114- ImportScope :: Block ( it) => ImportScope :: Block ( edit. make_mut ( it) ) ,
115- } ;
116- ide_db:: imports:: insert_use:: insert_use ( & scope, import, & ctx. config . insert_use ) ;
111+ let scope = ide_db:: imports:: insert_use:: ImportScope :: find_insert_use_container (
112+ import. syntax ( ) ,
113+ & ctx. sema ,
114+ ) ;
115+
116+ if let Some ( scope) = scope {
117+ let scope = match scope {
118+ ImportScope :: File ( it) => ImportScope :: File ( edit. make_mut ( it) ) ,
119+ ImportScope :: Module ( it) => ImportScope :: Module ( edit. make_mut ( it) ) ,
120+ ImportScope :: Block ( it) => ImportScope :: Block ( edit. make_mut ( it) ) ,
121+ } ;
122+ ide_db:: imports:: insert_use:: insert_use ( & scope, import, & ctx. config . insert_use ) ;
123+ }
117124 }
118125}
119126
0 commit comments