Skip to content

Instantly share code, notes, and snippets.

@tdegrunt
Forked from searls/.solargraph.yml
Created November 14, 2022 13:39
Show Gist options
  • Save tdegrunt/a44b3fe5062fd5454e11f7a96ef57f62 to your computer and use it in GitHub Desktop.
Save tdegrunt/a44b3fe5062fd5454e11f7a96ef57f62 to your computer and use it in GitHub Desktop.
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