Function ide_db::syntax_helpers::suggest_name::for_variable
source · pub fn for_variable(expr: &Expr, sema: &Semantics<'_, RootDatabase>) -> String
Expand description
Suggest name of variable for given expression
NOTE: it is caller’s responsibility to guarantee uniqueness of the name. I.e. it doesn’t look for names in scope.
§Current implementation
In current implementation, the function tries to get the name from the following sources:
- if expr is an argument to function/method, use parameter name
- if expr is a function/method call, use function name
- expression type name if it exists (E.g.
()
,fn() -> ()
or!
do not have names) - fallback:
var_name
It also applies heuristics to filter out less informative names
Currently it sticks to the first name found.