Prevent Eclipse setting breakpoint on Scala anonymous functions (lambdas) - eclipse

Using Scala plugin for Eclipse version 2.1 milestone 2, in Eclipse Indigo, if I set a breakpoint on a line that contains an anonymous function, e.g.
myList.map((x: String) => foo(bar(x)))
"the" breakpoint will be hit not only when map is called, but also when the anonymous function is called (it's actually multiple breakpoints, but frustratingly, they only show up as one breakpoint in the breakpoint tab in Eclipse). I think this is a regression, because I seem to remember you used to get multiple breakpoints showing up in this kind of case.
How can I stop Eclipse from treating the anonymous function as part of the same breakpoint?

Breakpoints are line-based, so just add newlines in such a way that it's still syntactically valid, but the lambdas you don't want to hit are now on separate lines. E.g.
myList.map(
(x: String) => foo(bar(x)))
(In my case, I still see an apparently spurious double-hit on the line, but that seems to be a different issue - it's not hitting the lambdas any more.)

Related

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 expression evaluation

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!

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

Highlight and replace arguments in autocompleted functions in PyDev interpreter

When I hit Ctrl-Alt-Enter in PyDev and begin typing a function name into the interpreter, PyDev helpfully offers a list of autocompletions. When I hit Enter, PyDev completes the function name and adds the parameter names, in parentheses. This would be great, except that the parameter names aren't highlighted, so I have to delete the parameters (or type an octothorpe) before I hit enter.
Is there a way either of making PyDev highlight the parameter names (ideally letting you tab to the next one, as it does in the editor) or of omitting them altogether? Having to manually delete the parameters defeats any efficiency gains from autocompletion.
Unfortunately this cannot be currently configured.
Still, you should be able to apply the completion with Ctrl+Enter (instead of only with Enter). That way the completion is applied without the arguments (nor the parenthesis -- which may not be 100% what you want) -- note that the same can be done in the PyDev editor, not only in the interactive console.
Please add this to the PyDev features tracker.

debug the last sentence of a program

I have used Eclipse and VS. When I insert a breakpoint and debug the program, it will stop before the breakpoint.
But what if I want to debug the effect of the last sentence of the program? Inserting a meaningless sentence(say print 'pause' in Python) is OK but seems awkward. Is there any alternatives?
In Visual Studio you can put break point on closing bracket in main (or any) method of Program (or any) class (default naming, may vary), then debugger stops just before closing application.
Is there any reason not to use a breakpoint on the last statement, like you said, then manually proceed one step? Depending on the debugger, this can also be automated. In GDB, one can use commands N, where N is the breakpoint number, to set a list of (debugger) commands to be executed immediately after a breakpoint is hit.