Professional Documents
Culture Documents
solargraph
Autocomplete, linting and
debugging with new ruby
tools
We promote the use of the ruby language, support the ruby job market, organize events to help
beginners through their learning journey and gather people around our core values: sharing, fun,
mutual respect.
We believe ruby has a big role to play in the Belgian tech ecosystem. Ruby is also a good starting
point for anyone who wants to learn to program.
#1 ASO Tool
for Apps & Games
Driven by Data Science
- Solargraph: What is it? How to make it work better for your project
- Solargraph + Rubocop: Making both work together, auto-correct from your editor
Solargraph is a Ruby gem that provides intellisense features through Microsoft's language server protocol.
Solargraph works with any editor that has a way to plug the LSP: VSCode, NeoVim, Emacs, etc
Then, you need to use it in your editor, for VSCode that means installing the Ruby Solargraph extension by Castwide.
It will index files on your project, but if you're using rails the out-of-the-box autocomplete is not that good either.
- If you use rails, you need to add the solargraph-rails plugin. It is a collection of annotations to help Solargraph
find its way around all the meta-programming.
Depending on the editor you're using, you might have some issues around having solargraph bundled/not bundled.
Solargraph, as most static analysis in Ruby, really has issues with meta-programming and DSLs, but you can improve it
with plugins, like the solargraph-rails, or by adding annotations:
# @!parse
# class ActiveRecord::Base
# extend ActiveRecord::QueryMethods
# extend ActiveRecord::FinderMethods
# extend ActiveRecord::Associations::ClassMethods
# include ActiveRecord::Persistence
# end
While rubocop is probably the most known linter for ruby, standard is being adopted by some projects to reduce bike
shedding around the rules.
rubyfmt has been making rounds as a fast formatter (it is partly written in rust), intended to be used at file save time.
Developed by stripe and being used internally.
If your solargraph setup is working as expected, you can also enable one extra thing: diagnostics.
Enabling "formatting" in the Solargraph options allows you to use the "format document" option from vscode based on
rubocop auto-correct.
This library provides debugging functionality to Ruby (MRI) 2.6 and later.
This debug.rb is replacement of traditional lib/debug.rb standard library which is implemented by set_trace_func. New
debug.rb has several advantages:
More in https://github.com/ruby/debug
Instead of adding debugging with binding.pry, the new method of debugging is using debugger.
Most commands (up, down, backtrace, etc) are similar, regular usage should not require a lot of adaptation.
Current version of debug is quite recent (May 2021) and it still has sub-par support for a few cases. Multi-thread mostly
works, but seems to break in random points.
You need to install the VSCode rdbg Ruby Debugger extension. Then, for each project you need a launch.json. vscode
will suggest a default one if you don't have one.