Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotkey to get type information for the selected expression #65890

Closed
alisabzevari opened this issue Jan 1, 2019 · 10 comments
Closed

Hotkey to get type information for the selected expression #65890

alisabzevari opened this issue Jan 1, 2019 · 10 comments
Assignees
Labels
editor-contrib Editor collection of extras editor-hover Editor mouse hover feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code
Milestone

Comments

@alisabzevari
Copy link

alisabzevari commented Jan 1, 2019

Intellij has a very useful feature called "show type info" that shows type information for the selected expression. For example, consider the following code:

function fn(count: number, str: string) {
	return str + count;
}

In Intellij IDEA it is possible to select str + count expression and press alt + = and get the result type of the selected expression (string in the example).

I think this feature would be very beneficial specially in the languages that type inference is very important. Although I am not sure this repository is the right place to ask for this feature.

@mjbvz mjbvz added feature-request Request for new features or functionality typescript Typescript support issues labels Jan 2, 2019
@mjbvz
Copy link
Collaborator

mjbvz commented Jan 2, 2019

Alternative: https://marketplace.visualstudio.com/items?itemName=MartinJohns.inline-types

TS can implement this using the existing VS Code apis. Not sure if there are enough other use cases that we need a dedicated api

@jrieken jrieken added editor-contrib Editor collection of extras editor-hover Editor mouse hover and removed typescript Typescript support issues labels Jan 3, 2019
@jrieken
Copy link
Member

jrieken commented Jan 3, 2019

@alisabzevari You can today already press Cmd+K Cmd+I to show the hover programmatically. That will show all hovers - usually it's just the type hover but it rare cases it might be more. Is that enough to make you happy?

@jrieken jrieken added the info-needed Issue requires more information from poster label Jan 3, 2019
@alisabzevari
Copy link
Author

So, here is a more interesting example:

import _ from "lodash";

const students = [
	{ id: 1, age: 20, points: [10, 12, 15] },
	{ id: 1, age: 25, points: [1, 12, 20] },
	{ id: 1, age: 18, points: [17, 10, 15] }
];

const sumAge = _.chain(students)
	.map(s => s.age)
	.sum()
	.value()

Usually, when dealing with chaining of calls, every function call (like map and sum) accept s certain input type and return a different type. Now, if I want to know what is the result type of _.chain(students).map(s => s.age).sum() it is only possible by removing the .value() in the end and look at the variable type by using Cmd+K Cmd+I.
In intellij it is possible to select a part of the expression and get type information for that selected part.

Here are some screenshots in intellij using this feature:
screenshot from 2019-01-03 21-19-15
As you can see, cursor is on articleId. Now if I press alt+= the following menu will open:
screenshot from 2019-01-03 21-19-20
So I can select which expression I want to get type info for. When I select Favorites.articleId, it shows the type info (only for that selected expression):
screenshot from 2019-01-03 21-19-24
Note that, generic type parameters are resolved here. If I select the other expression from the menu, the following result will appear:
screenshot from 2019-01-03 21-19-37
And here is another example, selecting the whole statement:
screenshot from 2019-01-03 21-19-43

This feature does not exist in vscode.

@jrieken jrieken removed the info-needed Issue requires more information from poster label Jan 7, 2019
@mjbvz
Copy link
Collaborator

mjbvz commented Jan 8, 2019

@jrieken One problem with the VS Code hover api and UX is that hover uses a position instead of a selection range. A hover provider could decide to use the current selection if the cursor position is within it but this could result in a confusing UX

@alisabzevari
Copy link
Author

I think this feature does not contradict with hover feature. This is how I image them together:

  • User can hover over (mouse cursor) an identifier and get type information for that identifier.
  • User can hit ctrl+k ctrl+i while not selecting anything and type information should be shown for the identifier currently under the caret (keyboard cursor).
  • User can hit ctrl+k ctrl+i to get type information for the currently selected expression.

@Ciantic
Copy link

Ciantic commented Jan 11, 2019

Now this is broken, I can't anymore copy & paste the type definition from the "Ctrl+K Ctrk+i", I get these darn abbreviations with three dots:

let ffprobe_video_stream: {
    index: number;
    codec_name: string;
    codec_long_name: string;
    profile: string;
    codec_type: string;
    codec_time_base: string;
    codec_tag_string: string;
    codec_tag: string;
    width: number;
    height: number;
    ... 22 more ...;
    tags: {
        ...;
    };
}

This thee dots abbreviation is some new addition, can we disable that? I constantly copy & paste the type definitions, ctrl+k ctrl+i is now useless for me.

EDIT I'm creating a bug report, this is bad: #66405

@jrieken jrieken added this to the Backlog milestone Jan 13, 2020
@mjbvz
Copy link
Collaborator

mjbvz commented Feb 27, 2021

Closing this since it has not gotten a significant number of 👍 over the past two years

@mjbvz mjbvz closed this as completed Feb 27, 2021
@mjbvz mjbvz added the *out-of-scope Posted issue is not in scope of VS Code label Feb 27, 2021
@ciuncan
Copy link

ciuncan commented Nov 14, 2022

This is a pretty significant missing feature in VS Code that I've been missin ever since I started using it. Type annotations are being used more and more frequently even by languages of dynamic nature like Python, TypeScript, etc. Coming from a Scala background, I've been using this feature of IntelliJ idea to get the inferred type of a selected expression. It is quite inconvenient to assign a selection to a variable each time just to see its type, not just coding yourself but especially if you are reviewing a code or reading a library source or a previous work.

I'd suggest reopening this issue as it is clearly not out of scope of VS Code since the type hint is already a feature of it.

@Troyx21
Copy link

Troyx21 commented Oct 14, 2023

Please reopen this!!!

@aksh1618
Copy link

I worked around this by remapping Show or focus hover (Ctrl+k Ctrl+i by default) to Ctrl+Shift+P (I'm coming from IntelliJ IDEA). This works for rust, although it shows the check/clippy lint etc. as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor-contrib Editor collection of extras editor-hover Editor mouse hover feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code
Projects
None yet
Development

No branches or pull requests

7 participants