komsit37 / sublime-q

Sublime Text Plugin for q/kdb
MIT License
24 stars 9 forks source link

Set breakpoints and debugger #11

Open danielkrizian opened 8 years ago

danielkrizian commented 8 years ago

Would debugging tool such as https://github.com/martomo/SublimeTextXdebug work with sublime-q?

Poor man's method of setting breakpoints such as this one with \e 1 toggle will freeze the Sublime Text session so individual lines can't be Ctrl+Enter'ed when trying to emulate stepping through the code in debug mode and examining the environment.

Helpful command-line debugger is https://github.com/quintanar401/dbg, but that's quite verbose as each step requires wrapping the operation into d2.xx[..]. Visual debugger within Sublime Text would be great!

komsit37 commented 8 years ago

Hi Daniel, Interesting. This should be doable but will require some work. I haven't looked at SublimeTextXdebug in details, but probably we can reuse the UI part and use https://github.com/quintanar401/dbg as a debuging engine.

Here is how I would do it

  1. load dbg.q in q session (can also bundle dbg.q with the plugin and load via REPL)
  2. wrap text from REPL in a function and wrap it again with .d2.i[...]
  3. wrap .d2.xxx[...] to step through the code, print environments, etc in a shortcut.

Here i s an example of how I implement show mem short cut (shift+f5) https://github.com/komsit37/sublime-q/blob/master/q_send.py

class QSendMemCommand(QSendCommand):
    def do(self, edit=None, input=None):
        input = '.Q.w[]'
        return super().do(input=input)

https://github.com/komsit37/sublime-q/blob/master/sublime/Default%20(Windows).sublime-keymap { "keys": ["shift+f5"], "command": "q_chain", "args": {"chain": ["q_send_mem", "q_out_panel"]}, "context":[{ "key": "selector", "operator": "equal", "operand": "source.q" }]}

The above should be straightforward. I think tricky part is how to deal with adding and removing breakpoint