Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Developing a Vim plugin with Ruby

Developing a Vim plugin with Ruby

Masafumi Okura

November 18, 2023
Tweet

More Decks by Masafumi Okura

Other Decks in Programming

Transcript

  1. Developing a Vim plugin with
    Ruby, or when in Ruby do as
    the Rubyists do
    VimConf 2023 Tiny
    OKURA Masafumi, 2023-11-18

    View full-size slide

  2. About me
    • Name: OKURA Masafumi


    • Company: nil (freelancer)


    • Specialty: Web development with Rails


    • Activities: Rubyist, Kaigi on Rails chief organizer, OSS maintainer
    (Alba), meetup organizer (Grow.rb, Rubygems Code Reading Meetup)


    • I brought some KoR swags today, talk to me to get one!


    • Vim user history: Vim (2013-2018), Neovim (2018-)

    View full-size slide

  3. VimConf and me
    • -2017: Attendee


    • 2018: Speaker (A day in the life of a (ordinary) Vimmer)


    • 2019: Organizer


    • After the conference, I was recommended to translate a book
    called “Mastering Vim” and I did it. It’s “ϚελϦϯάVim”


    • 2023: Speaker <- new!

    View full-size slide

  4. Your choice of
    the language

    View full-size slide

  5. …for the
    development of
    Vim plugins

    View full-size slide

  6. Language for the development of vim plugins
    1. Vim script


    2. Vim9 script


    3. Lua


    4. Deno

    View full-size slide

  7. Language for the development of vim plugins
    1. Vim script


    2. Vim9 script


    3. Lua


    4. Deno


    5. Ruby

    View full-size slide

  8. No one


    (I believe)

    View full-size slide

  9. Developing a Vim plugin with
    Ruby, or when in Ruby do as
    the Rubyists do
    VimConf 2023 Tiny
    OKURA Masafumi, 2023-11-18

    View full-size slide

  10. Developing a Vim plugin with
    Ruby, or when in Ruby do as
    the Rubyists do
    VimConf 2023 Tiny
    OKURA Masafumi, 2023-11-18

    View full-size slide

  11. When in Ruby

    View full-size slide

  12. When you want
    to manipulate
    Ruby code

    View full-size slide

  13. Do as the
    Rubyists do

    View full-size slide

  14. What do
    Rubyists do?

    View full-size slide

  15. Abstract


    Syntax


    Tree

    View full-size slide

  16. RubyVM::AbstractSyntaxTree

    View full-size slide

  17. RubyVM::AbstractSyntaxTree
    • Stdlib


    • No external dependencies


    • No need to install something via package managers


    • Takes Ruby source code as a String and returns AST root node


    • Not best for modifying code but good enough to get some
    information from code

    View full-size slide

  18. RSpec
    • One of the most famous testing libraries for Ruby


    • In fact, one of the most downloaded library


    • Introducing DSLs such as `describe`, `context`, `it` and `let`


    • Readable as English


    • These can be deeply nested


    • Tests can be implicit with `subject` and `is_expected`

    View full-size slide

  19. What is the
    current


    context/subject?

    View full-size slide

  20. rspec-current.vim

    View full-size slide

  21. Why not LSP?

    View full-size slide

  22. Why not LSP for this case?
    • Too trivial/niche


    • I cannot push this feature into generic LSP servers


    • Not enough functionality on extension/add-on/plugin system


    • ruby-lsp provides add-on system, but it’s immature now


    • Too many things to learn for only one feature


    • LSP is not the easiest thing to learn

    View full-size slide

  23. Ruby as a
    solution!

    View full-size slide

  24. Using Ruby as a development language
    • Simple/Easy


    • One
    fi
    le to work with, no external dependencies


    • Straightforward


    • Just plain Ruby code


    • Less things to learn


    • We need to learn how to develop a plugin with Ruby, but it’s
    simpler than learning LSP

    View full-size slide

  25. gem install neovim


    If you use Neovim

    View full-size slide

  26. Ruby heredoc

    View full-size slide

  27. Usecase for using
    Ruby as a
    development
    language for vim

    View full-size slide

  28. Language-
    speci
    fi
    c features

    View full-size slide

  29. Use your own
    language!

    View full-size slide

  30. Because you can

    View full-size slide

  31. Because of Vim

    View full-size slide

  32. Because Vim is
    so kind to let
    you do so

    View full-size slide

  33. Happy vimming!

    View full-size slide