Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTYPE: Add inlay parameter hints #1326
Conversation
This comment has been minimized.
This comment has been minimized.
farodin91
force-pushed the
farodin91:inlay-hints-provider
branch
from
cc752d9
to
06192ae
Jun 9, 2017
This comment has been minimized.
This comment has been minimized.
|
wow. let me try! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@farodin91 I found quite a lot of bugs :) |
This comment has been minimized.
This comment has been minimized.
|
I don't show type if i can't infer a type. |
farodin91
force-pushed the
farodin91:inlay-hints-provider
branch
from
06192ae
to
e65284c
Jun 9, 2017
This comment has been minimized.
This comment has been minimized.
|
Adding tests and Options |
This comment has been minimized.
This comment has been minimized.
|
But isn't |
This comment has been minimized.
This comment has been minimized.
|
Not now:) |
farodin91
force-pushed the
farodin91:inlay-hints-provider
branch
from
e65284c
to
4ae1a78
Jun 9, 2017
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
If you set the parameter it should infer parameters. For example |
This comment has been minimized.
This comment has been minimized.
|
@alygin Could you review? |
alygin
suggested changes
Jun 12, 2017
|
My main concern here is optionality of this feature. I think it must be possible to switch it off separately for the argument names and for the inferred types. IDEA has a special setting for it: "Editor -> General -> Appearance -> Show parameter name hints" with the "Configure..." button for extended settings, including per-language options. Unfortunately, other products (I looked in CLion) still don't have such block in the Preferences, so we need to add our own settings, probably to the "Langs & Frameworks -> Rust" panel ( PS: I'm on vacation now, so sorry for possible delays in my answers :) |
| val patBinding = ident.patBinding | ||
| val type = inferDeclarationType(patBinding) | ||
| if (type is TyUnknown || type is TyUnit) return emptyList() | ||
| return listOf(InlayInfo(": " + type.toString(), patBinding.textRange.endOffset)) |
This comment has been minimized.
This comment has been minimized.
| get() = reference.resolve() as? RsFunction | ||
|
|
||
| enum class HintType(desc: String, enabled: Boolean) { | ||
| LET_BINDING_HIST("Show local variable type hints", true) { |
This comment has been minimized.
This comment has been minimized.
| fun transform(index: Int, valueParameter: RsValueParameter, valueArgumentList: RsValueArgumentList): InlayInfo? { | ||
| if (index >= valueArgumentList.exprList.size) | ||
| return null | ||
| return InlayInfo(valueParameter.pat?.text + ":", valueArgumentList.exprList[index].textRange.startOffset) |
This comment has been minimized.
This comment has been minimized.
alygin
Jun 12, 2017
•
Contributor
You also need to return null here if valueParameter.pat? is null, to handle anonymous arguments properly. Here's a snippet to test this case:
trait Foo {
fn foo(&self, u32);
fn bar(&self) {
self.foo(10); // <-- shouldn't add `null: `
}
}
This comment has been minimized.
This comment has been minimized.
|
When calling a method using UFCS syntax, the labels are shifted by 1 for the extra self argument. struct S;
impl S {
fn foo_self(self, param1: u32) {}
fn foo_self_ref(&self, param1: u32) {}
fn foo_self_mut_ref(&mut self, param1: u32) {}
}
fn test() {
let mut b = S;
b.foo_self_ref(1);
b.foo_self_mut_ref(1);
b.foo_self(1);
S::foo_self_ref(&b, 1); //bad
S::foo_self_mut_ref(&mut b, 1); //bad
S::foo_self(b, 1); //bad
} |
This comment has been minimized.
This comment has been minimized.
|
@alygin For IDEA you can de/select a every single feature. Any idea to integrate it into rust settings panel and in the configure area? At the same time. |
farodin91
force-pushed the
farodin91:inlay-hints-provider
branch
from
4ae1a78
to
e97fdee
Jun 13, 2017
kumbayo
reviewed
Jun 15, 2017
| val ident = element.pat as? RsPatIdent ?: return emptyList() | ||
| val patBinding = ident.patBinding | ||
| val type = inferDeclarationType(patBinding) | ||
| if (type is TyUnknown || type is TyUnit) return emptyList() |
This comment has been minimized.
This comment has been minimized.
kumbayo
Jun 15, 2017
Contributor
Is there a reason / use case why you do not want to show the unit type on local variables?
Noise during typing new code?
I think it might be useful to show it for situations like.
let z = accidentally_returns_nothing();
fn accidentally_returns_nothing() -> () {
;
}
kumbayo
reviewed
Jun 15, 2017
| import com.intellij.psi.PsiElement | ||
| import org.rust.lang.core.psi.* | ||
| import org.rust.lang.core.psi.ext.RsCompositeElement | ||
| import org.rust.lang.core.psi.ext.valueParameters |
This comment has been minimized.
This comment has been minimized.
farodin91
force-pushed the
farodin91:inlay-hints-provider
branch
from
e97fdee
to
25b4588
Jun 18, 2017
This comment has been minimized.
This comment has been minimized.
|
Hm, compilation fails on 2016.3... I need to check if we can make extensions in |
This comment has been minimized.
This comment has been minimized.
|
But my implementation of settings shouldn't work in any case for 2016.3. |
This comment has been minimized.
This comment has been minimized.
|
It seems the |
This comment has been minimized.
This comment has been minimized.
|
@kumbayo Thank i pushed something wrong. |
farodin91
force-pushed the
farodin91:inlay-hints-provider
branch
3 times, most recently
from
b5ef4da
to
7c791bd
Jun 21, 2017
This comment has been minimized.
This comment has been minimized.
|
@matklad Any progress to fix compilation fails on 2016.3? |
This comment has been minimized.
This comment has been minimized.
|
@farodin91 looks like the easiest solution is just to wait while we drop support for 2016.3. This'll happen once 2017.2 is out, which is pretty soon. |
matklad
referenced this pull request
Jul 8, 2017
Closed
display function-parameter-hints automatically #1450
This comment has been minimized.
This comment has been minimized.
|
2017.2 just released |
This comment has been minimized.
This comment has been minimized.
|
I will rebase after #1487 is merged. |
farodin91
force-pushed the
farodin91:inlay-hints-provider
branch
from
7c791bd
to
f7623b5
Jul 19, 2017
This comment has been minimized.
This comment has been minimized.
|
Resolved |
This comment has been minimized.
This comment has been minimized.
|
@matklad Do you like to merge it? |
This comment has been minimized.
This comment has been minimized.
|
@farodin91 sure! bors r+ |




farodin91 commentedJun 9, 2017
•
edited
Fixes #1141