Scala and integrated terminal in VS Code

1.2k Views Asked by At

I am using the Scala REPL with the integrated terminal. I open the Scala REPL on the terminal and then send small snippets with

workbench.action.terminal.runSelectedText

(which I have bound to a shortcut). This works fine when the snippets have to be run literally. But sometimes when definitions are mutually recursive, Scala requires that I start the code with the command

scala> :paste

and then finish with a ctrl+d. Is there a way that I can automatically wrap the selected text in a ":paste" + selected_text + "^d"?

Thanks, Christian

1

There are 1 best solutions below

0
On

${selectedText} variable holds currently selected text, and sendSequence supports variable substitution, hence in Open Keyboard Shortcuts (JSON) try adding

[
    {
      "key": "cmd+shift+T",
      "command": "workbench.action.terminal.sendSequence",
      "args": {
        "text": ":paste\u000D${selectedText}\u000D\u0004"
    }
]

where \u0004 is Control+D, and \u000D is Enter. Now try

  1. start console from sbt
  2. select the source code you want to paste in console
  3. Hit cmd+shift+T