How do I view the type of a scala expression in IntelliJ
ScalaIntellij IdeaScala Problem Overview
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?
Scala Solutions
Solution 1 - Scala
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.
Solution 2 - Scala
On OS X, it's ctrl + shift + P for me. This shows the exact type with resolved generics.
Solution 3 - Scala
CTRL / Command key and hover over the variable or method.
Solution 4 - Scala
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.
Solution 5 - Scala
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.
Solution 6 - Scala
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.
Solution 7 - Scala
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.
Solution 8 - Scala
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).
Solution 9 - Scala
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 likectrl
+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.
Solution 10 - Scala
In Windows . Alt + = In mac . option + =