rust-analyzer
                                
                                 rust-analyzer copied to clipboard
                                
                                    rust-analyzer copied to clipboard
                            
                            
                            
                        Feature request: Inline type alias
Similar to "Inline function" / "Inline into all callers", it would be nice if there was "Inline typealias" and "Inline into all uses" for type aliases.
Was thinking about this yesterday, would’ve been nice for https://github.com/rustls/rustls/pull/895.
I'll try to implement this.
@Veykril It seems we can close this issue?
Hey @hi-rustin, #11690 only added inlining a single instance of a type alias use, this feature also requests inlining the definition to all users.
I'm going to try this one
Hi @steven-joruk! Currently I'm trying to implement inline_alias_uses.
You added a nice test: https://github.com/rust-lang/rust-analyzer/blob/49700e46366bfe7958204877b4edcf74987ec508/crates/ide-assists/src/handlers/inline_type_alias.rs#L385-L398
which shows that the current implementation can't inline such alias uses.
IIUC, this happens because ctx.find_node_at_offset::<ast::PathType>() invocation returns None, and we have no alias instance to work with.
Could you please explain, why ctx.find_node_at_offset behaves in such a way? This is my first issue in rust-analyzer so I have very little understanding of things :smile:
An ast::PathType specifically is an ast::Path that appreas in type position, as an example let PathPat: PathType = PathExpr;.
So to support inlining on usages, we should be checking ctx.find_note_at_offset::<ast::Path>(), then check the parent node of that path and act accordingly.
Besides calling an associated function on an aliased type, there seems to be a lot of other usages. (Enum variant, Record expression, etc)
What is more important that needs to be done first, cover as much usages as possible in inline_type_alias or implementing a basic version of inline_type_alias_uses that works only for PathType?
By the way, I'm not sure I understand, what does Path represent?
A Path is just something like foo::bar::Baz or foo on its own as well. PathType, PathPat, PathExpr etc just wrap a Path then depending on whether it is a type, pattern expression
It doesnt really matter what you improve herefirst, thats up to you