On Sublime Text Ruby Integrations

To make Sublime Text convenient for Ruby here’s what I recommend.

Running tests

Usually I run tests externally, in iTerm2. That’s because I want to use interactive terminal when using binding.irb. iTerm2 has path recognition, so you can click on the path under the failing test, and see it open in the editor. This setting is under your Profile -> Advanced -> Semantic History.

For added convenience, install the package RubyTest (old but still works) to be able to run current file (cmd+shift+e) or current test under cursor (cmd+shift+r) right within Sublime Text.

Rubocop

Use ruby-lsp and ruby-lsp-rails, it will automatically highlight Rubocop issues. Here’s my Sublime LSP config. All features are enabled by default.

{
  "show_inlay_hints": true,
  "clients":
  {
    "ruby-lsp": {
      "enabled": true,
      "command": ["ruby-lsp"],
      "selector": "source.ruby",
      "initializationOptions": {
        "experimentalFeaturesEnabled": true
      }
    }
  },
}

You can find my preferred rubocop settings in narrative Rails template. I try to keep them up to date.

Worth noting, that at the time of this writing:

  1. ERB files are not yet supported (which is why selector is only source.ruby).
  2. Autocomplete is limited to requires, class names.
  3. CodeLenses (to show inline actions to run tests) need custom integration that doesn’t exist for Sublime Text.

Erb linting and Ruby warnings

A couple of things that are nice to auto-highlight in the editor are Ruby warnings, and Erb issues. That’s why despite LSP, SublimeLinter is still useful.

Install SublimeLinter, and its plugin SublimeLinter-ruby for warning lint.

I also added a custom linter for Shopify’s erb-lint. There is an existing one, but it could be improved, which is why I put an issue on there. Among other things, this linter will run your Rubocop config on your erb files. Not all cops will play well with erb, which is why erb-lint lets you disable some of them in its own config.

Editing

I use multiAlign for vertical alignment, NeoVintageous for vim mode, and Wrap Plus for cmd+opt+q wrapping of code comments at 80 col line width.

Status bar

I keep my status bar minimal. At some point it got overloaded with various git-related noise, so I decided to dig in, clean it up, and it’s actually useful to me now. It looks like this:

492 Words, ~2m 27s, LSP-copilot, ruby-lsp, ok, Line 148, Column 36

When I write prose, I like to see words and reading time (thanks to WordingStatus package). Then a sanity check for which LSP servers are operational (it does show current line issue when there’s one, might get rid of that). Then Ruby warnings, and line/column.

Theme and Font

My current favorite light theme for Sublime is Tricolore by Martin (zeroelink). This preference tends to change every now and then.

For the dark theme, I’ve been absolutely in love with Chelevra Ayu by Jonas Hermsmeier (github) for years, and don’t think this will be changing any time soon. It’s the perfect minimal color balance that lets me focus on code. And an awesome shade of green.

My absolute favorite coding font, after many years of trying different ones, is Input Mono Condensed, which I use for both iTerm2 and Sublime Text.

Other notable packages

Here’s the quick list of other notable packages I use:

  • ApplySyntax — good at assigning correct syntaxes to various ambiguous files based on their path, context.
  • FileDiffs — quick diff between editor tabs.
  • GitGutter — I like it better than Sublime’s built-in change marks.
  • GitSavvy — I rarely actually use it, but sometimes it’s convenient to look at current file’s history. Most git operations I do in iTerm2, and Fork.app — the latter being especially useful for picking individual lines for selective commits.
  • LSP-copilot — I subscribe to Github’s Copilot.
  • PlainTasksTODO list formatting (usually keep an open .todo file in a split pane on the bottom).
  • Profile Switcher — quick switch between multiple configurations. I have a custom keyboard shortcut for switching between light and dark color scheme (cmd+shift+x, cmd+shift+c), as well as separate Light/Dark profiles for writing prose. Btw, my iTerm2 also uses the same shortcut to switch between light and dark.
  • SideBarEnhancement — the most convenient way to create, rename, and move files for me.


Date
November 14, 2023