Debugging expression evaluation - scala

I'm using IntelliJ idea Community edition (with Scala) and I'm trying to evaluate an expression. I hit Alt-F8 to open it in debug mode and then switch to 'Code Fragment Mode'. However, I'm allowed to only evaluate variables that already exist in memory, and am not allowed to declare new. When I do so, I get- 'Evaluation of variables is not supported'. Is there a plugin that I can use in debug mode to evaluate arbitrary code?
EDIT: So that it's clear, no worksheets are not what I'm looking for. I want to evaluate expressions using variables existing at runtime.

Have you considered using a Scala Worksheet, which is a kind of editor supported REPL. You can create one in your project, import code from your project, execute it and see the results instantly. It wont let you debug to a piece of code though, if that is your primary intention.

It's an old question, but for now there is a good answer:
https://www.jetbrains.com/help/idea/2016.1/evaluating-expressions.html
TL;DR: During debugging, click on a stack frame, and you'll be able to evaluate expressions in the context of that frame: Run|Evaluate Expression, and you can click "Code Fragment Mode" to enter multi-line stuff. IntelliJ autocomplete features would work properly too!

Related

VSCode GoToDefinition behaviour - can't just go to next nest

When you have to work with STM32 HAL you know, there is many macros and sometimes you want to know where is implemented this one. In my example, in line 40 i use F12 on label PROSTE_MAKRO (F12 is GoToDefinition). In my case this function directs me to line 30, where is defined macro SRC, not my PROSTE MAKRO what i expect. It looks like this VSCode function GotoDefinition think to much how to (NOT!) help me and evaluate my macro to basic forms. But half of code i have in HAL is macros and i expect gotoDefinition shoud redirect me by any (if is more than one) nested definition. I want it and this is how many IDE works.
I use Visual Studio Code with Plaftormio and C/C++ Microsoft extension. I have configure c_cpp_properties.json file with my configuration name, paths etc. I've made all toolchain from EmbeddedGeek yt video, but it all works good. (STM32F767 code generation and flashing is ok).
I have no idea wtf is wrong with VSCode but any day give me new reason to hate VSC.
I'm trying ask google about it but ofc i've reveive zero answer. I'm trying change goto behavior in general settings (13 setting found) but always it work wrong. I have record it on YT so you can watch it: https://www.youtube.com/watch?v=5FADq5yRp6g
And now i think SO is my last option.
In file: .vscode\c_cpp_properties.json in field:
"intelliSenseMode": "windows-msvc-x86",
"compilerArgs": [],
"compilerPath": ""
I have defined my toolchain compiler and it's args. VScode automatic recognize it and think it is something different than default and change Intellisense mode to other (in my case it was arm-gcc or so). And it is. I have delete my compliler path and compiler args and leave it empty. Now GoToDefinition (default F12) work good.
But be careful - if you change "intelliSenseMode" to windows-msvc-x86 but set compiler path and args VSCode will inform you that intelliSenseMode is different than you try set. In any case - don't touch it.

Interactive debug console for scala in Intellij?

I am learning scala in my free time. When I was programming in python with Pycharm, Pycharm provides a very handy tool called debug console which, if I set a breakpoint at line L, would store the value of the variables by the time of L, and I can freely explore some operations on those variables.
I know scala has a REPL tool and I am wondering if scala in Intellij IDEA has the similar debug console. I know I can use evaluate expression tool but it is a little difficult to use because
I can't see the previous calculated expression values and I have to retype every time to see the values.
I can't store the result of the expression on one variable and continue using that variable.
Thanks!
If you set a breakpoint on a line (click in left margin to get a red dot) and then Debug rather than Run (bug icon rather than play icon) then IntelliJ will stop at the first breakpoint and show a very comprehensive debugging window. You can evaluate an expression (calculator icon) and create a watch expression which is evaluated each time a breakpoint is hit (watch panel on the right).

Debugging functions in matlab

Question: Is there a preferred way to debug functions in matlab?
If I all calculations in a script, then every variable is in the workspace and I can easily query them to find out what's not working right. However, if I use a function, then only my outputs are visible and I can't see what's going wrong. I understand there are ways of getting around this, but thusfar they seem to be more trouble than just making one, long ugly, script. So how do YOU debug functions in matlab? Is there a preferred/efficient way of doing this?
I always make sure to enable "Stop If Error" in the Breakpoints menu and if I want to debug a specific function I set a breakpoint at the first line in that function (or at the point of interest). Note that "clear all", which is common in the beginning of scripts deletes all break points. Use "clear variables" instead.
See MATLAB settings - stop if errors for more info on how to make the Stop If Error persist when you restart Matlab.

Using IntelliJ IDE to autocomplete line and place semi-colon

In eclipse you can hit "enter" and the IDE will automatically take you to the end of the line and place a semicolon.
In IntelliJ, if you hit shift-enter you get similar behavior minus adding the semicolon. I have read and tried cntrl-shift-enter and you get the exact same behavior. However, that is such an awkward key combination to be using all the time, at least much more so than the one-button approach using Eclipse.
Any ideas?
IntelliJ autocomplete escape
In InteiJ IDEA use (Ctrl-Shift-Enter) for "Smart Autocomplete".
It will end the line "smartly" with a semicolon as you wish. It also works in a few different situations like IF statements of FOR loops.
Why don't you redo the key binding?
Go to: (spanner icon) Settings -> Keymap -> Complete Current Statement and rebind how you will (for example, ctrl-enter might suit you better).
Or there's also a default keymap set for Eclipse that you can choose. I'm not sure if it affects the complete-current-line action, but you could take a look.
you can also use ctrl+shift+space
if you want always have it just do this

Clearing output from Scala Worksheet

Every-time you save a Scala Worksheet in the Scala IDE, the output of each expression is printed as comments on the right-hand side of the editor. Is there a way to clear this output from a Scala Worksheet so that you can cut and paste code?
Currently, my solution is to save my worksheet with an error, so that the output would disappear. There must be a better way... a keyboard shortcut or something.
There is no such feature yet. There is a related ticket: The Format action should strip comments.
While waiting for the ticket to be resolved, this regular expression can be used in Find/Replace (Ctrl/Cmd+F) to delete the comments.
*//[>|].*$
Update:
This has been fixed: #132
It's jerry-rigged, but gets the job done.
Make a small edit (e.g. delete a space where it doesn't matter) to prompt a save.
Save.
Press Esc immediately to terminate worksheet process.
You now have a clean worksheet!
Ctrl+Shift+C does the job in Scala IDE 4.7.0
Alt+Shift+A enables Block selection mode. You will be able to select only left part of screen (columns with code). Block mode also makes possible to select only columns with output.
More on block selection mode