Skip to content

Instantly share code, notes, and snippets.

@castwide

castwide/rails.rb

Last active Nov 28, 2020
Embed
What would you like to do?
Enhance Rails Intellisense in Solargraph
# 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.
#
# You can put this file anywhere in the project, as long as it gets included in
# the workspace maps. It's recommended that you keep it in a standalone file
# instead of pasting it into an existing one.
#
# @!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>]
@castwide

This comment has been minimized.

Copy link
Owner Author

@castwide castwide commented Jun 25, 2019

I updated the gist to take advantage of some changes in Solargraph 0.34.0. The require calls are no longer needed, I added a few more mixins, and the @!override directive is an experimental feature for supplementing documentation from external gems. See castwide/solargraph#87 for more information.

@thornomad

This comment has been minimized.

Copy link

@thornomad thornomad commented Jul 2, 2019

I am trying to extend this to use additional ActiveRecord class methods (in this example, where) ... is this the right approach?

# @!override ActiveRecord::QueryMethods#where
#   @overload where(str)
#     @param str [String]
#     @return [Class<self>]
#   @overload where(list)
#     @param list [Array]
#     @return [Class<self>]
#   @overload where(**options)
#     @param options [Hash]
#     @return [Class<self>]
@castwide

This comment has been minimized.

Copy link
Owner Author

@castwide castwide commented Jul 2, 2019

The issue with ActiveRecord::Relation we discussed in castwide/solargraph#188 still applies, but yeah, I think that's generally the right idea.

@RobertLowe

This comment has been minimized.

Copy link

@RobertLowe RobertLowe commented Oct 25, 2020

@castwide missing # extend ActiveRecord::Persistence::ClassMethods no?

@guledali

This comment has been minimized.

Copy link

@guledali guledali commented Oct 25, 2020

You should extend the actioncontroller with the render, redirect and strong parameters

#   class ActionController::Base
#     include ActionController::MimeResponds
#     include ActionController::Redirecting
#     include ActionController::StrongParameters
#     include AbstractController::Rendering
#     extend ActiveSupport::Callbacks::ClassMethods
#     extend AbstractController::Callbacks::ClassMethods
#   end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.