Solargraph: Global autocomplete variables/identifiers

Created on 8 Feb 2020  路  2Comments  路  Source: castwide/solargraph

Is it possible to define global variables for autocomplete? Let me explain what I mean:

current_user is used magically everywhere. This is almost generally an User model.

Is it possible to define this variable as User globally across workspace? So when i type current_user. it will auto-complete user model always and everywhere

I have definitions.rb on root which is based on your Rails tweaks from another issue.

Most helpful comment

You have a few different options. If you want it to be truly global, you could use the @!method directive on Kernel:

# @!method current_user
#   @return [User]
module Kernel; end

But you could also apply it to specific classes or modules:

# @!method current_user
#   @return [User]
class ApplicationController < ActionController::Base
  # ...
end

The second option makes current_user visible in all of your controllers (i.e., any subclass of ApplicationController).

Depending on your app's architecture, there might be some other module where you could apply the directive for better accuracy.

All 2 comments

You have a few different options. If you want it to be truly global, you could use the @!method directive on Kernel:

# @!method current_user
#   @return [User]
module Kernel; end

But you could also apply it to specific classes or modules:

# @!method current_user
#   @return [User]
class ApplicationController < ActionController::Base
  # ...
end

The second option makes current_user visible in all of your controllers (i.e., any subclass of ApplicationController).

Depending on your app's architecture, there might be some other module where you could apply the directive for better accuracy.

Awesome!

Thanks Fred! 馃帀馃帀

Was this page helpful?
0 / 5 - 0 ratings