Are there any IDE or editors integrated with leiningen, such that leiningen tasks can be dispatched by them, and if or when they throw an exception in your code, they jump you to the source file and line where the exception arises?
For example, I would like to lein test or lein compile upon saving a source file, and jump to the offending line of code if an exception is thrown during the task's execution.
Sure, Cursive does that very well. It's a plugin for IntelliJ IDEA.
Now, that's only possible when REPLing from within IntelliJ, and I don't think it does auto-compile on save, but that's possible with just one keyboard shortcut.
As for calling leiningen tasks from the IDE, yes you can via the "External Tools" feature. But you can also run tests from the REPL by invoking the test functions.
Emacs with CIDER displays
the exception when you eval something (e.g., your file, C-c C-k) and you can hit
Enter to visit the trigger.
Many provided shortcuts let you run tasks like test.
Here is
a list of CIDER's bindings. You can also see Clojure mode bindings right in Emacs
with C-h RET.
And, you can see many of the other CIDER/task commands by simply pressing C-c, if you install helm-descbinds. Most of the CIDER bindings happen to be shown in the right column.
Lastly, you can type M-x cider- to see a list of many (~100) unbound commands.
Related
I've been working with Clojure for few weeks now, primarily with Lein+Luminus framework. I've been looking for a way to debug code while on the REPL.
I really like the way how pry(on Ruby) works, when it comes to debugging and runtime invocation. Is there an equivalent to pry for clojure code? or probably a technique/tool that I've missed?
There are two paths to consider to improve your REPL and debugging experience:
Using a REPL and debugger integrated with your editor or IDE of choice
Using an embedded nREPL server
The first is an essential part of setting up your local Clojure development environment and should be done regardless. The second option, using an embedded nREPL server, is closer in usage to how you would use a binding.pry call in your code since it gives you access to the running application, but it isn't used to stop execution at a certain point, but rather give you a REPL with access to your running application and it doesn't provide any additional debugging features on its own.
Editor/IDE with REPL and Debugger
Text editors like Emacs and Vim have excellent Clojure support (both for editing and interacting with a REPL), and most Java IDE's have Clojure support as well.
At this point (May 2015) I'd highly recommend trying Jetbrain's Intellij IDEA with the Cursive plugin because of its excellent support for debugging. You can use the free community edition of Intellij, and the Cursive plugin is (at this point) free as well.
Intellij IDEA
To install Cursive, you go into Intellij's settings, add the correct Cursive plugin repository for the version of Intellij you have, install Cursive, and restart the IDE.
Once Cursive is active, you can simply open an existing Leiningen project in Intellij via "File > Open...". To get a REPL running, click "Run > Edit Configurations" in the main menu. In the window that appears, click the "+" button at the top left and select "Clojure REPL > Local". I'd change the name of the run configuration from "Unnamed" to something like "REPL", but otherwise keep the defaults and press "OK" to save the run configuration.
Now you have a way to run a REPL set up for the project you've opened. You can now click "Run > Run 'REPL'" (or whatever you named that run configuration) for a normal REPL, or better yet click "Run > Debug 'REPL'" to boot up the REPL in a debug mode that allows you to use Intellij's debugging features to debug your Clojure code. Set break points, add breakpoint conditions, run code and inspect frames, variables, etc., like you would in any debugger.
In your case, you'd want to click "Run > Debug 'REPL'" and then execute in that REPL the code you use to boot up your application.
Embedded nREPL Server
The above approach assumes that you first start a Clojure REPL and then boot up your application. If instead you want to have your application boot up normally and then optionally get a REPL that lives inside the running Clojure program, using nREPL directly is your best option.
From its own README:
nREPL is a Clojure network REPL that provides a REPL server and client, along with some common APIs of use to IDEs and other tools that may need to evaluate Clojure code in remote environments.
You should follow these instructions to add a running nREPL server to your application, but here is the most important part:
=> (use '[clojure.tools.nrepl.server :only (start-server stop-server)])
nil
=> (defonce server (start-server :port 7888))
#'user/server
Once you have a running nREPL server as part of your Clojure application, you can attach to it using your editor or IDE of choice (each editor/IDE has a different way of doing this, but most expose a way to attach to a running REPL by providing the host (usually localhost) and the port on which an nREPL server is running), or by invoking Leiningen directly at the command-line like this:
lein repl :connect <port>
You can specify the <port> when you configure the nREPL server as shown above. It also prints it out when it starts.
clj-debugger is a basic REPL debugger which provides features pretty similar to those available in pry-debug. You might consider it as an alternative to using the debuggers available in tools like CIDER & Cursive.
debugging is a huge problem in clojure as we are not aware of where the error occurred as well. define this macro :
(defmacro dbg[x] `(let x# ~x to understand where the eroor is thrown
I've tried to install Leiningen according to the official installation instructions. When running lein repl I get the following error message:
/usr/local/bin/lein: line 315: java: command not found
This leads me to believe that Leiningen requires a JDK/JRE to actually run but there is no mention of it in the docs. So, do I first need to install a JDK/JRE?
Yes, see installation instruction https://github.com/technomancy/leiningen#installation
Yes, you need to install JDK first.
Instruction for Windows installation is here
Leinengen comes packaged as a JAR file with a small bash script wrapping it, allowing for easy command line usage. This means that, like any other clojure or java program, it require the JVM to be run.
If you take a look at ~/.lein/self-installs/ you will see the JAR file(s) leiningen utilizes to run it's tasks.
One thing worthy of noting as well is that Leiningen starts its own JVM process before creating a new JVM process for your clojure program. They are not run in the same JVM container (to enforce isolation). Also, this initial Leiningen JVM process will not close until your clojure program has finished running as well (unless you utilize the trampoline).
As always, it's worth reading through the Leiningen docs at some point to better learn about what leiningen is truly doing. Hopefully that helps... happy coding!
There is already a thread here that partially answers my question .
On Eclipse 3.7.2 I followed the approach provided there and I could successfully accomplish the steps creating and setting up a new error parser and adding it to my current project. After executing my Boost.Test (boost rel. 1.48.0) Unit Test, on the Eclipse console I get the same output as the output I get when no parsing is done (e.g. when executing the Unit Test outside Eclipse (e.g. on a Linux terminal)). I searched for a new Eclipse console where the parsed Unit Test output could be displayed (similar to the consoles by e.g. gcov, gprof or cppcheck in Eclipse) but found nothing alike.
Where should the parsed unit test output be displayed? In case the parsed output shall be displayed in the Eclipse Console view, are there any suggestions what might have gone wrong with the parsing in my case?
Thanks in advance.
P.S.: Thanks to casperOne and kleopatra for teaching me manners.
If you're using Eclipse there is also a really nice plugin called TestRunner for running CDT unit tests much like Java or Python unit tests. It handles the unit-testing parsing for you. You'll get a separate console window for your unit tests and it arranges them with level filters. Clicking on an error/warning takes you to the unit-test line number in your editor. You also can set the verbosity level as well as a few other settings from inside Eclipse.
You can directly install the plugin by using the following link in Eclipse updates https://raw.github.com/xgsa/cdt-tests-runner/tests_runner_demo/testsrunner/org.eclipse.cdt.testsrunner-updatesite/site.xml
In order to eclipse parse errors, the error must be print in the console view at compile time. If you are emitting errors in runtime, you must add your program to be called by the Makefile.
That's how I do in embedded systems.
I have a C++ project with a SWIG-generated Python front-end, which I build using CMake. I am now trying to find a convenient way to debug my mixed Python/C++ code. I am able to get a stack-trace of errors using gdb, but I would like to have some more fancy features such as the ability to step through the code and set breakpoints, for example using Eclipse.
Using the Eclipse generator for CMake I am able to generate a project that I am able to import into Eclipse. This works fine and I am also able to step through the pure C++ executables. But then the problem starts.
First of all, I am not able to build the Python front-end from inside Eclipse. From command line I just do "make python", but there is no target "python" in the Eclipse project.
Secondly, once I've compiled the Python front-end, I have no clue how to step through a Python script that contains calls to my wrapped C++ classes. Eclipse has debugging both for Python and for C++, but can they be combined?
some more fancy features such as the ability to step through the code and set breakpoints, for example using Eclipse
how are those features "fancy"? You can already do those in pdb for Python, or gdb for C++.
I'd suggest running the python code with pdb (or using pdb.set_trace() to interrupt execution at an interesting point), and attach gdb to the process in a separate terminal. Use pdb to set breakpoints in, and step through, your Python code. Use gdb to set breakpoints in, and step through, your C++ code. When pdb steps over a native call, gdb will take over. When gdb continue allows Python execution to resume, pdb will take over.
This should let you jump between C++ and Python breakpoints without needing to trace through the interpreter.
Disclaimer: I largely think IDEs are rubbish bloatware, so if Eclipse does have a good way to integrate this, I wouldn't know about it anyway.
Currently the gdb console of Eclipse just connects the stdin/stdout between the java gui and the underlying gdb process, hence many gdb shell features are missing, e.g. tab-autocomplete, command history etc.
I want to know if there is an enhanced console for fast gdb interacting. I really like the frequently used gdb commands like "print" and "call" etc. IMHO, "print" command is superiors sometimes than Eclipse "Expression watcher" because it only execute once and the later will be evaluated any time and be crash-prone.
If you think there is no need to use gdb console, then what's you best-practise in terms of gdb UI to eclipse UI transfer.
There doesn't seem to be any gdb-specific plugin, beside the initial gdb integration initiated with Eclipse3.4.
And the current list of gdb bugs doesn't include your missing features.
If you're writing c/++, why not just find the eclipse-generated elf and use gdb via the shell?