Skip to content

Instantly share code, notes, and snippets.

@DRBragg
Last active April 13, 2024 01:43
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save DRBragg/92903ce7e902076c4c0e2ebd5e3ddf0c to your computer and use it in GitHub Desktop.
Save DRBragg/92903ce7e902076c4c0e2ebd5e3ddf0c to your computer and use it in GitHub Desktop.
My config with steps to use solargraph for Rails projects in VS Code (WIP)
---
include:
- "app/**/*.rb"
- "config/**/*.rb"
- "lib/**/*.rb"
exclude:
- spec/**/*
- vendor/**/*
- ".bundle/**/*"
require:
- actionmailer
- actionpack
- actionview
- activejob
- activemodel
- activerecord
- activesupport
domains: []
reporters:
- rubocop
- require_not_found
- typecheck
- update_errors
formatter:
rubocop:
cops: safe
except: []
only: []
extra_args: []
require_paths: []
plugins:
- solargraph-rails
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>]
  • Install the Ruby Solargraph VS Code extension and configure to your projects bundler path.
  • 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.
  • In your Project root run $ solargraph config
    • Optional: Update the generated file with the config above (This is for my project YMMV)
  • In your Project root run $ solargraph bundle
  • Add the contents of this gist to your project (or see above). I keep mine in config/definitions.rb
  • In your Project root run $ yard gems
  • Restart VS Code
  • Profit?

These steps are mostly from memory

@danest
Copy link

danest commented Apr 13, 2024

Thank you! This was helpful for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment