Skip to content

Instantly share code, notes, and snippets.

@searls
Forked from DRBragg/.solargraph.yml
Last active August 2, 2023 09:14
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save searls/13912eccce10dac7e07c76db8ea96ef7 to your computer and use it in GitHub Desktop.
Save searls/13912eccce10dac7e07c76db8ea96ef7 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
@jnunemaker
Copy link

Does someone who copies this need to run solargraph bundle and yard gems on a regular basis?

@searls
Copy link
Author

searls commented Jan 18, 2023

Hey Nunes! In truth I never got this to work. My setup is still not in a state I could recommend :(

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