Jon Freedman
Jon Freedman

Reputation: 9687

How do I view the type of a scala expression in IntelliJ

The Eclipse scala plugin has a nice feature which shows you the type of a variable when you hover the mouse over it. How do I see the same information with the IntelliJ plugin?

Upvotes: 137

Views: 59610

Answers (10)

piritocle
piritocle

Reputation: 342

For OS X, use ctrl + J on a variable, function or signature to get full definition, type, and parameters. Use ctrl + shift + P for evaluated type (this also works on highlighted code block or expression).

Upvotes: 3

Pushpendra Jaiswal
Pushpendra Jaiswal

Reputation: 470

In Windows . Alt + = In mac . option + =

Upvotes: 0

Erik van Oosten
Erik van Oosten

Reputation: 1728

In IntelliJ 2016 and later with Mac OS X 10.5+ keybindings the keybinding is Ctrl++P.

Old answer:

Under MacOS with Mac OS X 10.5+ keybindings, it is supposed to be +=, however that does not seem to work at all (for me).

In the settings (Preferences > Keymap and enter "Type Info" in the search field), I added the shortcut Ctrl++T to the action. This shortcut works fine.

Upvotes: 20

Andrew
Andrew

Reputation: 569

You can set IntelliJ up sort of like eclipse. Go to:

File -> Settings -> Languages & Frameworks -> Scala

and then tick "Show type info on mouse hover after, ms" and set your preferred timeout.

This works well except that other messages seem to take preference. The most common being "Declaration is never used" which is quite a lot of the time if you have just written a val and want to see it's type. Then you have to resort to (Alt + =) for PC or (Ctrl + Shift + P) forMac.

Upvotes: 23

Zoltán
Zoltán

Reputation: 22146

On OS X, it's ctrl + shift + P for me. This shows the exact type with resolved generics.

Upvotes: 54

Sergey Passichenko
Sergey Passichenko

Reputation: 6920

Select expression and type Alt + =.


If you want to change the shortcut go to Preferences > Keymap and enter "Type Info" in the search field.

In older versions, it's Shift + Ctrl + Alt + T.

Upvotes: 131

akauppi
akauppi

Reputation: 18036

There's good tips gathered around here, but since the mappings vary by the keyboard bindings, here's a summary for the Mac OS X 10.5+ bindings.

  • ctrl + hover: show the type of the expression

  • alt + hover: clicking on the expression inspects its value (very handy!)

  • + hover works like ctrl+hover, but also allows clicking the link to go to other references of the expression (ctrl+click obviously doesn't because it is regarded as right click in OS X).

Note: The Mac OS X 10.5+ bindings are still not the default in IntelliJ 13.1, but they really should be. They have a more native OS X feel than the old Mac OS X bindings. You can activate them via Preferences > "keyboard" (in the search field) > Keymap > Keymaps: Mac OS X 10.5+

The real usability problem with these (as of IntelliJ 13.1) is that one needs to hold the key, then move the cursor. It should ideally also work when you have the cursor already on the expression, then start keeping ctrl/alt/cmd pressed in. I'll request them for this.

ps. I know it's OS X, officially, not Mac OS X. IntelliJ IDEA still uses the old naming at least for the keycaps.

Upvotes: 1

Paweł Krupiński
Paweł Krupiński

Reputation: 1426

CTRL / Command key and hover over the variable or method.

Upvotes: 37

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 340708

You can hit Ctrl + Q on a variable or method signature to view its type.

There is also a neat trick to view type of any expression: select the expression and type Ctrl + Alt + V. This will show Extract variable dialog with expression type to be extracted shown for convenience.

Upvotes: 36

Dave Griffith
Dave Griffith

Reputation: 20515

Hold down the Command key as you mouseover. Note: I tested this on Mac OS X with standard keybindings. Different OSes or non-standard keybindings may of course be different, but the functionality is certainly there.

Upvotes: 5

Related Questions