Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My config with steps to use solargraph for Rails projects in VS Code (WIP)
---
include:
- ".solargraph_definitions.rb"
- "app/**/*.rb"
- "config/**/*.rb"
- "lib/**/*.rb"
exclude:
- test/**/*
- vendor/**/*
- ".bundle/**/*"
require:
- actionmailer
- actionpack
- actionview
- activejob
- activemodel
- activerecord
- activesupport
domains: []
reporters:
- standardrb
- require_not_found
- typecheck
- update_errors
require_paths: []
plugins:
- solargraph-rails
- solargraph-standardrb
max_files: 5000
# The following comments fill some of the gaps in Solargraph's understanding of
# Rails apps. Since they're all in YARD, they get mapped in Solargraph but
# ignored at runtime.
#
# @!parse
# class ActionController::Base
# include ActionController::MimeResponds
# extend ActiveSupport::Callbacks::ClassMethods
# extend AbstractController::Callbacks::ClassMethods
# end
# class ActiveRecord::Base
# extend ActiveRecord::QueryMethods
# extend ActiveRecord::FinderMethods
# extend ActiveRecord::Associations::ClassMethods
# extend ActiveRecord::Inheritance::ClassMethods
# include ActiveRecord::Persistence
# end
# @!override ActiveRecord::FinderMethods#find
# @overload find(id)
# @param id [Integer]
# @return [self]
# @overload find(list)
# @param list [Array]
# @return [Array<self>]
# @overload find(*args)
# @return [Array<self>]
# @return [self, Array<self>]

Set up:

  • Install the Ruby Solargraph VS Code extension and disable Use Bundler
  • Run $ gem install solargraph solargraph-rails
  • Update the Ruby Solargraph VS Code extension's command path to point to the abolute path of your solargraph install. (e.g. /Users/justin/.rbenv/shims/solargraph)
  • Add the contents of this gist to the root of the project and git ignore them
  • In your project root run $ solargraph bundle
  • In your project root run $ yard gems
  • Run the Developer: Reload Window command for VS Code

Verify

  • Visit your app/models/application_record.rb
  • Navigate over the Base in ApplicationRecord::Base
  • Right-click Peek -> Peek Definition and the pop-up view should include a reference to base.rb from inside the `activerecord gem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment