Hello everyone, I am a new Ruby Su enthusiast. I successfully linked su through the RubyMine debugger documentation on GitHub, and the threads and variables show that they are connected. But what should I do next to debug my code, as there is no response after linking. The su program interface is also the interface I usually open. Is this normal? I think there should be a place to run the code I’m learning, but I can’t find the location
Oh, let me add that there is no corresponding program in the extension program
You can paste code into SketchUp’s Ruby Console if you must.
Thank you very much for your answer, sir, but I pasted my code in su console and didn’t hit a breakpoint, even if I hit a breakpoint in rubymine does that mean the environment for successful debugging has not been configured yet
I think you misunderstood me. Pasting code into the console and running it is very manual debugging and has nothing to do with breakpoints that you’ve set in Rubymine.
There are already several topics dedicated to debugging SketchUp extensions with Rubymine.
Search results for ‘debugger Rubymine #developers:ruby-api’ - SketchUp Community
Perhaps you may not understand that SketchUp extension code is event driven. Meaning that is usually the user doing some event that fires a method in your code. This can be clicking a button on the toolbar, choosing an item on a menu, pressing a key on the keyboard, making a selection of geometry in the model, or adding or deleting model objects, etc.
This has already been said, but I’ll repeat: the simplest and often sufficient way to debug is to write puts statements into your code at critical places and have the SketchUp Ruby Console open to see what they write.
The interaction between a debug ide and the Ruby interpreter embedded in SketchUp is mainly file-based. That is, many of the commands and responses in the dialog between them refer to line numbers and variable names in a file. So, if the ide doesn’t know the file you are trying to debug, it can’t do things such as set breakpoints because the debug protocol for them uses line numbers in a file. You need to load a file into SketchUp and point the ide at that same file so that the protocol they share makes sense to both of them.
Then, as @DanRathbun noted, you need to do something that causes SketchUp’s event-driven Ruby to start running your code. Otherwise it just sits there and waits.
The most primitive way is to include a top-level expression in your code that invokes some method defined in the code. A downside of this technique is that you have to reload your code each time you want to see its debug output.
When using a debug ide, an action via the GUI that triggers your extension’s code is the most common way. If your code implements a Tool, the right way is to activate that Tool via the SketchUp GUI. If your code just defines methods, you can invoke them via the SketchUp Ruby Console - but be aware that you must provide the correct name scope or the interpreter won’t know what you are talking about (all code should be wrapped in modules to avoid contamination of the global namespace shared with all of Ruby).
That said, many debug ide’s provide limited ways to probe code without an identified source file. For example, VSCode, which I use, has a console in which you can type Ruby expressions and it will pass them to SketchUp for execution regardless of GUI state. I don’t know RubyMine, so you’ll have to look for an equivalent yourself.
These expressions can use any names known to the Ruby interpreter regardless of the file they came from. This is much like typing into the SketchUp Ruby Console, but it works even if the interpreter is stopped at a breakpoint. Watch expressions also cause the interpreter to run snippets of code. In VSCode I often set watch expressions on some instance @ variables because its debug interface does not otherwise display them (probably a limitation of the particular implementation of the debug protocol I use).