37

When an implicit conversion is applied, IntelliJ underlines the converted code. Is it possible to navigate to the applied conversion in some way?

Diego
  • 5,024
  • 6
  • 38
  • 47

2 Answers2

39

Yes it is possible (IntelliJ IDEA 11.1.3 CE with Scala Plug-In 0.5.948, but this has been possible for a while).

You need to select the receiver not the method itself. For instance, assume dataDir is of type java.io.File. Then I can do

dataDir.listFiles().foreach( ... )

where foreach is available through implicit conversion from Array to ArrayOps, thus is underlined. If you select dataDir.listFiles() and choose from the menu Navigate -> Implicit Conversion (shortcut Ctrl-Q), a popup menu shows you all possible conversions, and selects the conversion currently applied.

enter image description here

0__
  • 66,707
  • 21
  • 171
  • 266
  • 10
    +1, you are right. However the shortcut is Ctrl+Shift+Q, at least on my machine (Ubuntu) ;-). I'll delete my answer as soon as it's unaccepted (can't do it now). – Tomasz Nurkiewicz Aug 20 '12 at 15:48
  • I'm on OS X. There was a problem with the shortcut before, because it was occupied by an OS-wide function, that's probably why it got changed. Indeed, the current version has an _additional_ defunct shortcut `Alt-Return` :-/ – 0__ Aug 20 '12 at 15:51
  • WOW, a year of work without knowing it existed. I was always looking for the implicits manually, thanks – lisak Sep 25 '14 at 05:58
  • How do I know which one is actually used in the list? There are so many and I have to check them one by one :( – Freewind Aug 09 '15 at 11:18
  • @Freewind the one that is initially selected in the list, that's the one applied. – 0__ Aug 10 '15 at 14:33
  • There are more details [on this IDEA wiki page](https://confluence.jetbrains.com/display/IntelliJIDEA/Working+with+Scala+Implicit+Conversions) – Mifeet Aug 29 '15 at 10:08
  • There is also another option: selecting the value, pressing Alt+Return and selecting `Provide implicit conversion` intention will make the used implicit conversion explicit. – Mifeet Aug 29 '15 at 13:00
  • Very cool. I just need to determine which implicit is applied, without IntelliJ, in the REPL. `:t` does not give the answer. Any ideas? Thanks – Peter Becich Jul 29 '16 at 06:11
12

As above but the shortcut in Windows/Linux is Ctrl+Shift+Q.

Maciej Falski
  • 249
  • 3
  • 7