@@ -16,6 +16,14 @@ pub struct ItemCandidate {
1616 pub module_path : String ,
1717}
1818
19+ /// A type alias discovered in source with its resolved module path.
20+ #[ derive( Clone ) ]
21+ pub struct TypeAliasCandidate {
22+ pub item : syn:: ItemType ,
23+ pub line_number : usize ,
24+ pub module_path : String ,
25+ }
26+
1927/// Returns candidates of `kind` in `module_path`, optionally requiring `required_attr`.
2028pub fn candidates_in_module (
2129 file_path : & str ,
@@ -84,6 +92,45 @@ pub fn plain_item_line_in_module(
8492 }
8593}
8694
95+ /// Returns type aliases of `alias_name` declared in `module_path`.
96+ pub fn type_aliases_in_module (
97+ file_path : & str ,
98+ module_path : & str ,
99+ alias_name : & str ,
100+ ) -> Vec < TypeAliasCandidate > {
101+ let Some ( analysis) = get_file_analysis ( file_path) else {
102+ return Vec :: new ( ) ;
103+ } ;
104+
105+ let mut candidates = analysis
106+ . type_aliases
107+ . iter ( )
108+ . filter ( |entry| entry. item . ident == alias_name)
109+ . filter_map ( |entry| {
110+ let resolved_module = module_path_for_line ( file_path, entry. line_number ) ?;
111+ ( resolved_module == module_path) . then ( || TypeAliasCandidate {
112+ item : entry. item . clone ( ) ,
113+ line_number : entry. line_number ,
114+ module_path : resolved_module,
115+ } )
116+ } )
117+ . collect :: < Vec < _ > > ( ) ;
118+ candidates. sort_by ( |left, right| {
119+ left. item
120+ . ident
121+ . to_string ( )
122+ . cmp ( & right. item . ident . to_string ( ) )
123+ . then ( left. module_path . cmp ( & right. module_path ) )
124+ . then ( left. line_number . cmp ( & right. line_number ) )
125+ } ) ;
126+ candidates. dedup_by ( |left, right| {
127+ left. item . ident == right. item . ident
128+ && left. module_path == right. module_path
129+ && left. line_number == right. line_number
130+ } ) ;
131+ candidates
132+ }
133+
87134/// Formats candidates for user-facing diagnostics.
88135pub fn format_candidates ( candidates : & [ ItemCandidate ] ) -> String {
89136 candidates
0 commit comments