📜 ⬆️ ⬇️

Vim ruby ​​debugger

Until recently, I wrote Ruby code in Netbeans. The stuff is cool and very convenient, but I’ve been staring at Vim for a long time, it was too much of a powerful text editor, I never dreamed of bean. I tried to switch to it several times, but as soon as I met a plug-in in the code, I closed Vim, opened Netbeans, set a breakpoint and started to figure out what was wrong. In general, I got used to the debugger.

Having suffered for some time, the idea came to write Ruby debugger under Vim. Opened the code rails.vim, NERDTree.vim and began to learn VimScript'u. So thanks to tpope and Marty Grenfell for the lessons (although they probably will never read it or find out about it). The plugin can now be seen on github .

What can a plugin


1. Debug any Ruby scripts using ruby-debug-ide gem.
2. Set / delete breakpoints, view variables, travel through the code.
3. Enter commands manually. For example ,: RdbCommand p Post.all will display all Post model entries.

What is required


To work correctly, the plugin should:
  1. Vim version> = 7.0, compiled with the + signs and + clientserver options . You can check it like this:
    ')

    :echo has("signs") && has("clientserver") && v:version >= 700

    The result should be = 1
  2. Fixed ruby-debug-ide gem
  3. If you are on Linux, you need lsof installed

Installation

  1. Clone repo:

    git clone git://github.com/astashov/vim-ruby-debugger.git

  2. From the resulting we need only the vim folder, the rest is needed only for development. Copy the contents of vim to ~ / .vim / (or to vimfiles if you are under Windows).

    As a result, there should be 3 files:
    • plugin / ruby_debugger.vim - the plugin itself
    • doc / ruby_debugger - documentation
    • bin / ruby_debugger.rb is an intermediate Ruby script between Vim and a ruby-debug-ide gem. All communication between them takes place through it.

  3. Next, run Vim and execute



    :helptags ~/.vim/doc

    to install plugin documentation. You can read it on command

    :help ruby-debugger

Installation completed!

Using

  1. Run Vim. If you use gvim, it will automatically start the Vim server, and if vim, you need to start it with the servername option: vim --servername VIM
  2. For example, we are going to a rail project.
  3. We start the server with a debugger command

    :Rdebugger

    (by default it starts the script / server webrick, if you need to debug another script, you can run:

    :Rdebugger foo.rb

  4. We set a breakpoint somewhere (by default, the command <Leader> b , most often it is \ b).
  5. Open a page with a breakpoint in the browser. Vim should automatically jump to the line with a worked breakpoint.
  6. We look further at variables, we travel on the code, in general - we have fun! :)

Teams


By default (of course, you can override them in your .vimrc) such abbreviations are added:

How to override them you can read in : help ruby-debugger-details

If you met a bug or came up with a cool new feature


Then I will be wildly grateful for the report in the gitkhabovsky Issues. You can also just write on anton / sbc / astashov.net, but the report in Issues will be better. :) The plugin logs almost all of its actions to the ~ / .vim / tmp / ruby_debugger_log file, so it is advisable to attach the contents of this file along with the bug.

I checked the performance in Linux and Windows. In Linux, the plugin works better; in Windows, I still do not understand how to start processes in the background, so the flickering windows with the server and the intermediate ruby ​​script are distracting. I didn't check it in MacOs, because I don't have it.

And finally, a screenshot of the plugin:
Screenshot Vim Ruby Debugger

Source: https://habr.com/ru/post/59731/


All Articles