@@ -123,13 +123,47 @@ impl Backend {
123123 // 4. Try each candidate class and pick the first one where the
124124 // member actually exists (directly or via inheritance).
125125 for target_class in & candidates {
126+ // Check if the member name is a trait `as` alias on this class.
127+ // If so, resolve to the original method name and (optionally) the
128+ // source trait so we jump to the actual method definition rather
129+ // than failing to find an alias that only exists after inheritance
130+ // resolution.
131+ let ( effective_name, alias_trait) =
132+ Self :: resolve_trait_alias ( target_class, member_name) ;
133+
134+ // If we know the exact source trait from the alias, go directly
135+ // to that trait's method definition.
136+ if let Some ( ref trait_name) = alias_trait {
137+ if let Some ( trait_info) = class_loader ( trait_name) {
138+ if Self :: classify_member ( & trait_info, & effective_name, access_hint) . is_some ( ) {
139+ if let Some ( ( class_uri, class_content) ) =
140+ self . find_class_file_content ( & trait_info. name , uri, content)
141+ && let Some ( member_position) = Self :: find_member_position (
142+ & class_content,
143+ & effective_name,
144+ MemberKind :: Method ,
145+ )
146+ && let Ok ( parsed_uri) = Url :: parse ( & class_uri)
147+ {
148+ return Some ( Location {
149+ uri : parsed_uri,
150+ range : Range {
151+ start : member_position,
152+ end : member_position,
153+ } ,
154+ } ) ;
155+ }
156+ }
157+ }
158+ }
159+
126160 let declaring_class =
127- Self :: find_declaring_class ( target_class, member_name , & class_loader)
161+ Self :: find_declaring_class ( target_class, & effective_name , & class_loader)
128162 . unwrap_or_else ( || target_class. clone ( ) ) ;
129163
130164 // Check that the member is actually present on the declaring class.
131165 let member_kind =
132- match Self :: classify_member ( & declaring_class, member_name , access_hint) {
166+ match Self :: classify_member ( & declaring_class, & effective_name , access_hint) {
133167 Some ( k) => k,
134168 None => continue , // member not on this candidate, try next
135169 } ;
@@ -138,7 +172,7 @@ impl Backend {
138172 if let Some ( ( class_uri, class_content) ) =
139173 self . find_class_file_content ( & declaring_class. name , uri, content)
140174 && let Some ( member_position) =
141- Self :: find_member_position ( & class_content, member_name , member_kind)
175+ Self :: find_member_position ( & class_content, & effective_name , member_kind)
142176 && let Ok ( parsed_uri) = Url :: parse ( & class_uri)
143177 {
144178 return Some ( Location {
@@ -155,15 +189,45 @@ impl Backend {
155189 // and try the original (non-iterating) logic so we at least get
156190 // partial results when possible.
157191 let target_class = & candidates[ 0 ] ;
158- let declaring_class = Self :: find_declaring_class ( target_class, member_name, & class_loader)
159- . unwrap_or_else ( || target_class. clone ( ) ) ;
160192
161- let member_kind = Self :: classify_member ( & declaring_class, member_name, access_hint) ?;
193+ let ( effective_name, alias_trait) =
194+ Self :: resolve_trait_alias ( target_class, member_name) ;
195+
196+ // Direct trait lookup for aliased members in the fallback path.
197+ if let Some ( ref trait_name) = alias_trait {
198+ if let Some ( trait_info) = class_loader ( trait_name) {
199+ if let Some ( ( class_uri, class_content) ) =
200+ self . find_class_file_content ( & trait_info. name , uri, content)
201+ && let Some ( member_position) = Self :: find_member_position (
202+ & class_content,
203+ & effective_name,
204+ MemberKind :: Method ,
205+ )
206+ && let Ok ( parsed_uri) = Url :: parse ( & class_uri)
207+ {
208+ return Some ( Location {
209+ uri : parsed_uri,
210+ range : Range {
211+ start : member_position,
212+ end : member_position,
213+ } ,
214+ } ) ;
215+ }
216+ }
217+ }
218+
219+ let declaring_class =
220+ Self :: find_declaring_class ( target_class, & effective_name, & class_loader)
221+ . unwrap_or_else ( || target_class. clone ( ) ) ;
222+
223+ let member_kind =
224+ Self :: classify_member ( & declaring_class, & effective_name, access_hint) ?;
162225
163226 let ( class_uri, class_content) =
164227 self . find_class_file_content ( & declaring_class. name , uri, content) ?;
165228
166- let member_position = Self :: find_member_position ( & class_content, member_name, member_kind) ?;
229+ let member_position =
230+ Self :: find_member_position ( & class_content, & effective_name, member_kind) ?;
167231
168232 let parsed_uri = Url :: parse ( & class_uri) . ok ( ) ?;
169233 Some ( Location {
@@ -380,6 +444,23 @@ impl Backend {
380444 ///
381445 /// Returns `Some(ClassInfo)` of the declaring class, or `None` if the
382446 /// member cannot be found in any ancestor.
447+ /// Resolve a trait `as` alias on a class.
448+ ///
449+ /// If `member_name` matches a trait alias declared on the class, returns
450+ /// the original method name and (optionally) the source trait name.
451+ /// Otherwise returns `member_name` unchanged with no trait hint.
452+ fn resolve_trait_alias ( class : & ClassInfo , member_name : & str ) -> ( String , Option < String > ) {
453+ for alias in & class. trait_aliases {
454+ if alias. alias . as_deref ( ) == Some ( member_name) {
455+ return (
456+ alias. method_name . clone ( ) ,
457+ alias. trait_name . clone ( ) ,
458+ ) ;
459+ }
460+ }
461+ ( member_name. to_string ( ) , None )
462+ }
463+
383464 fn find_declaring_class (
384465 class : & ClassInfo ,
385466 member_name : & str ,
0 commit comments