Stream: t-compiler/wg-rls-2.0

Topic: Difference between `name` and `func_name`


Avishay Matayev (Mar 03 2020 at 19:24, on Zulip):

This is related to the completion function add_function_with_name at crates/ra_ide/src/completion/presentation.rs.

What exactly is the difference between name and func_name?func_name is always present and retrieved from the db, but name is expected to be potentially absent and will use func_name in such case.

Currently there is only flow that passes name as Some - add_resolution but I don't really understand what exactly resolutions are in this context. Is this to support the use X as Y; syntax?

Florian Diebold (Mar 03 2020 at 19:28, on Zulip):

it looks like it, though it doesn't seem like it's working fully (rust-analyzer#3356) :confused:

Florian Diebold (Mar 03 2020 at 19:31, on Zulip):

changing the code to always use func_name makes no tests fail :disappointed:

Florian Diebold (Mar 03 2020 at 19:31, on Zulip):

so I guess it was supposed to handle that, but is probably broken

Florian Diebold (Mar 03 2020 at 19:33, on Zulip):

name is whatever the name that resolved to the function was, which becomes mostly relevant in the case of use X as Y, yeah

Avishay Matayev (Mar 03 2020 at 19:33, on Zulip):

I see. Perhaps the name of the variables can be changed to be more clear about their purpose whenever this feature is fixed ;d

Florian Diebold (Mar 03 2020 at 19:35, on Zulip):

and there is no name in the case of method calls, like something.foo() or SomeType::foo() (name will be None and func_name will be "foo")

Avishay Matayev (Mar 03 2020 at 19:37, on Zulip):

yeah but notice that name is re-evaluated if it is None; let name = name.unwrap_or_else(|| func_name.to_string());

Florian Diebold (Mar 03 2020 at 19:37, on Zulip):

yeah, that's why

Florian Diebold (Mar 03 2020 at 19:38, on Zulip):

for method calls, we need the actual declared name, for other calls, we need the name under which the function was actually imported

Florian Diebold (Mar 03 2020 at 19:38, on Zulip):

I think the use of func_name later in the function is wrong and should be name as well

Avishay Matayev (Mar 03 2020 at 19:39, on Zulip):

Thanks, I understand.

Avishay Matayev (Mar 03 2020 at 19:39, on Zulip):

I think you are right as well

Avishay Matayev (Mar 03 2020 at 19:39, on Zulip):

it makes no sense to use the original name when it was imported under a different name

Avishay Matayev (Mar 03 2020 at 19:40, on Zulip):

(at least for the snippet itself)

Florian Diebold (Mar 03 2020 at 19:42, on Zulip):

yes. I think I'll just fix it... and I think it actually needs more fixing for other item types

Florian Diebold (Mar 03 2020 at 19:43, on Zulip):

ah no, for other items it works

Avishay Matayev (Mar 03 2020 at 19:44, on Zulip):

Cool, can you ping me whenever you are done? I am working on https://github.com/rust-analyzer/rust-analyzer/issues/1705 now and I'm sure we'll conflict

Florian Diebold (Mar 03 2020 at 19:48, on Zulip):

https://github.com/rust-analyzer/rust-analyzer/pull/3430

Avishay Matayev (Mar 03 2020 at 19:50, on Zulip):

That was quick!

Florian Diebold (Mar 03 2020 at 19:51, on Zulip):

a bit too quick, I forgot to update the snapshot at first ;)

Last update: Sep 30 2020 at 15:30UTC