Is there a quick way to show the code of a method declared in the Scala console?

I often use the Scala console to evaluate and verify code before I actually wrote it in my project. If I want to know the contents of a variable, I can just enter it, and Scala will evaluate it. But is there a way to show the code of the introduced methods?

I know that the UP key shows single lines, but what I was looking for is to show all the code at once.

+6
source share
2 answers

There is a file in your home directory called .scala_history that contains all of your recent REPL history. I regularly copy and paste the code from this file into the project source files. This is not exactly the same as showing code for individual methods in REPL, but it can help you achieve the same goals.

See Paul Phillips's comments on this issue for a discussion of some of the related functions in the REPL (grouping statements in history):

At some point, I implemented the logic for this, but the real hurdle is jline. He has enough problems when it turns out where the cursor is located on the simplest conditions. Start throwing large multi-line blocks into a story and it breaks in tears. I would like to see this and SI-2547, addressed by the community.

...

I will fix this soon too, but it depends on how well the recent jline work goes. I implemented it a long time ago, and problems with displaying an obstacle.

Both of these comments are older than two years, so I would not hold my breath.

+7
source

I do not know the command to download all the code from the command line. What you can do is :load path/to/my/file.scala load some complex code and re :load when you change the code in the file.

+1
source

Source: https://habr.com/ru/post/920892/


All Articles