Design trade-offs for completion item name shadowing in rust-analyzer #21480
CubeSugarCheese
started this conversation in
General
Replies: 1 comment 2 replies
-
|
How will this prevent |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
current problem
In rust-analyzer, there is a problem exist for many yaers
#18398 Don't auto import items when one is already in scope
#17164 Block specific items from being auto-imported
The most common examples as follows
current ra will give auto-complete hint like this
if you push enter to auto-complete, you will complete and import anyhow::Ok instead of core::result::Result::Ok. That's really annoying.
In #17164, Veykril mention that "we should filter out auto-importing completions if they shadow something that's in scope".
I try modify ra to impl this feature, but it casued now preblem.
Let's imagine a lib (just call it foo) provide a type alias
type Result<T> = core::result::Result<T, FooError>;User may
use foo::Resultto shadowcore::result::Result, but we already filter it out of alternative list, so user lose there completions.How about rustc?
For rustc, there is no import sequence, all imports are treat with same rules as follows.
Namespace is type of name, in current rust, only 3 types of namespace, they are Types, Values and Macros.
For simple, all
namein follow list refer (name, namespace) pair.baris defined multiple timeswhat rust-analyzer needs to solve?
After considering the order and the fact that RA will not use wildcard imports, there is 2 conditions needs to solve.
a.already exist named import
ra will give hint
use std::alloc::Layout.b.already exist wildcard imports
ra will give hint
use anyhow::Ok.possible solution
std::alloc::Layoutalloc::Layoutuse std::alloc::Layout as Layout1use std::alloc::Layout as AllocLayoutI prefer a with 1 and 4, b with 1 and 3.
Because full path import easy to implement, other methods require a loop check for conflicts in the super path names to obtain the shortest path.
Beta Was this translation helpful? Give feedback.
All reactions