@@ -6,6 +6,7 @@ use ra_text_edit::TextEditBuilder;
66use rustc_hash:: FxHashMap ;
77
88use crate :: completion:: { CompletionContext , CompletionItem , CompletionKind , Completions } ;
9+ use hir:: { ModPath , PathKind } ;
910
1011pub ( super ) fn complete_scope ( acc : & mut Completions , ctx : & CompletionContext ) {
1112 if !ctx. is_trivial_path {
@@ -54,58 +55,76 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
5455 }
5556}
5657
57- fn build_import_label ( name : & str , path : & [ SmolStr ] ) -> String {
58+ fn build_import_label ( name : & str , path : & ModPath ) -> String {
5859 let mut buf = String :: with_capacity ( 64 ) ;
5960 buf. push_str ( name) ;
6061 buf. push_str ( " (" ) ;
61- fmt_import_path ( path , & mut buf ) ;
62+ buf . push_str ( & path . to_string ( ) ) ;
6263 buf. push_str ( ")" ) ;
6364 buf
6465}
6566
66- fn fmt_import_path ( path : & [ SmolStr ] , buf : & mut String ) {
67- let mut segments = path. iter ( ) ;
68- if let Some ( s) = segments. next ( ) {
69- buf. push_str ( & s) ;
70- }
71- for s in segments {
72- buf. push_str ( "::" ) ;
73- buf. push_str ( & s) ;
74- }
75- }
76-
7767#[ derive( Debug , Clone , Default ) ]
7868pub ( crate ) struct ImportResolver {
7969 // todo: use fst crate or something like that
80- dummy_names : Vec < ( SmolStr , Vec < SmolStr > ) > ,
70+ dummy_names : Vec < ( SmolStr , ModPath ) > ,
8171}
8272
8373impl ImportResolver {
8474 pub ( crate ) fn new ( ) -> Self {
75+ use hir:: name;
76+
8577 let dummy_names = vec ! [
86- ( SmolStr :: new( "fmt" ) , vec![ SmolStr :: new( "std" ) , SmolStr :: new( "fmt" ) ] ) ,
87- ( SmolStr :: new( "io" ) , vec![ SmolStr :: new( "std" ) , SmolStr :: new( "io" ) ] ) ,
88- ( SmolStr :: new( "iter" ) , vec![ SmolStr :: new( "std" ) , SmolStr :: new( "iter" ) ] ) ,
89- ( SmolStr :: new( "hash" ) , vec![ SmolStr :: new( "std" ) , SmolStr :: new( "hash" ) ] ) ,
78+ (
79+ SmolStr :: new( "fmt" ) ,
80+ ModPath { kind: PathKind :: Plain , segments: vec![ name![ std] , name![ fmt] ] } ,
81+ ) ,
82+ (
83+ SmolStr :: new( "io" ) ,
84+ ModPath { kind: PathKind :: Plain , segments: vec![ name![ std] , name![ io] ] } ,
85+ ) ,
86+ (
87+ SmolStr :: new( "iter" ) ,
88+ ModPath { kind: PathKind :: Plain , segments: vec![ name![ std] , name![ iter] ] } ,
89+ ) ,
90+ (
91+ SmolStr :: new( "hash" ) ,
92+ ModPath { kind: PathKind :: Plain , segments: vec![ name![ std] , name![ hash] ] } ,
93+ ) ,
9094 (
9195 SmolStr :: new( "Debug" ) ,
92- vec![ SmolStr :: new( "std" ) , SmolStr :: new( "fmt" ) , SmolStr :: new( "Debug" ) ] ,
96+ ModPath {
97+ kind: PathKind :: Plain ,
98+ segments: vec![ name![ std] , name![ fmt] , name![ Debug ] ] ,
99+ } ,
93100 ) ,
94101 (
95102 SmolStr :: new( "Display" ) ,
96- vec![ SmolStr :: new( "std" ) , SmolStr :: new( "fmt" ) , SmolStr :: new( "Display" ) ] ,
103+ ModPath {
104+ kind: PathKind :: Plain ,
105+ segments: vec![ name![ std] , name![ fmt] , name![ Display ] ] ,
106+ } ,
97107 ) ,
98108 (
99109 SmolStr :: new( "Hash" ) ,
100- vec![ SmolStr :: new( "std" ) , SmolStr :: new( "hash" ) , SmolStr :: new( "Hash" ) ] ,
110+ ModPath {
111+ kind: PathKind :: Plain ,
112+ segments: vec![ name![ std] , name![ hash] , name![ Hash ] ] ,
113+ } ,
101114 ) ,
102115 (
103116 SmolStr :: new( "Hasher" ) ,
104- vec![ SmolStr :: new( "std" ) , SmolStr :: new( "hash" ) , SmolStr :: new( "Hasher" ) ] ,
117+ ModPath {
118+ kind: PathKind :: Plain ,
119+ segments: vec![ name![ std] , name![ hash] , name![ Hasher ] ] ,
120+ } ,
105121 ) ,
106122 (
107123 SmolStr :: new( "Iterator" ) ,
108- vec![ SmolStr :: new( "std" ) , SmolStr :: new( "iter" ) , SmolStr :: new( "Iterator" ) ] ,
124+ ModPath {
125+ kind: PathKind :: Plain ,
126+ segments: vec![ name![ std] , name![ iter] , name![ Iterator ] ] ,
127+ } ,
109128 ) ,
110129 ] ;
111130
@@ -115,7 +134,7 @@ impl ImportResolver {
115134 // Returns a map of importable items filtered by name.
116135 // The map associates item name with its full path.
117136 // todo: should return Resolutions
118- pub ( crate ) fn all_names ( & self , name : & str ) -> FxHashMap < SmolStr , Vec < SmolStr > > {
137+ pub ( crate ) fn all_names ( & self , name : & str ) -> FxHashMap < SmolStr , ModPath > {
119138 if name. len ( ) > 1 {
120139 self . dummy_names . iter ( ) . filter ( |( n, _) | n. contains ( name) ) . cloned ( ) . collect ( )
121140 } else {
0 commit comments