Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby's Standard Libraries Are Not Loaded Automatically #54

Open
ali-p-q opened this issue Dec 31, 2022 · 2 comments
Open

Ruby's Standard Libraries Are Not Loaded Automatically #54

ali-p-q opened this issue Dec 31, 2022 · 2 comments

Comments

@ali-p-q
Copy link

ali-p-q commented Dec 31, 2022

Describe the bug
Rails automagically loads Ruby's standard libraries (e.g. SecureRandom), but solargraph-rails does not. This bug is probably related to issue #53

To Reproduce
Steps to reproduce the behavior:

  1. Create a class (e.g. class User < ApplicationRecord)
  2. Invoke the method SecureRandom.urlsafe_base64 in the scope of the class

Expected behavior
Docs and autocomplete should be available for both SecureRandom and the method urlsafe_base64.

Actual behavior
No docs or autocomplete.

Workaround
Add the line # require 'securerandom' to the definitions.rb file under all classes in the inheritance chain (see screenshots below).

Screenshots
Workaround
image

Debug log

[INFO] Indexing workspace files in ./
[DEBUG] [Rails][Schema] added ["name", "email", "created_at", "updated_at", "password_digest", "remember_digest"] to User
[DEBUG] [Rails][RailsApi] added ["ActiveRecord::ConnectionAdapters::SchemaStatements", "ActiveRecord::ConnectionAdapters::SchemaStatements"] to CreateUsers
[DEBUG] [Rails][RailsApi] added ["ActiveRecord::ConnectionAdapters::SchemaStatements", "ActiveRecord::ConnectionAdapters::SchemaStatements"] to AddIndexToUsersEmail
[DEBUG] [Rails][RailsApi] added ["ActiveRecord::ConnectionAdapters::SchemaStatements", "ActiveRecord::ConnectionAdapters::SchemaStatements"] to AddPasswordDigestToUsers
[DEBUG] [Rails][RailsApi] added ["ActiveRecord::ConnectionAdapters::SchemaStatements", "ActiveRecord::ConnectionAdapters::SchemaStatements"] to AddRememberDigestToUsers
[INFO] Loading gems for bundler/require
[DEBUG] [Rails][Rails] found 33 pins in annotations
[INFO] Loading rails 7.0.4 from /home/ali/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/doc/rails-7.0.4/.yardoc
[INFO] Loading bundler 2.3.26 from /home/ali/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/doc/bundler-2.3.26/.yardoc
[INFO] Loading bundler stdlib from cache
[INFO] Loading bootsnap 1.15.0 from cache
[INFO] Loading msgpack 1.6.0 from cache
[INFO] Loading securerandom stdlib from cache
[INFO] Loading rake 13.0.6 from cache
[INFO] Loading concurrent-ruby 1.1.10 from cache
[INFO] Loading i18n 1.12.0 from cache
[INFO] Loading minitest 5.16.3 from cache
[INFO] Loading tzinfo 2.0.5 from cache
[INFO] Using cached documentation for activesupport at /home/ali/.solargraph/cache/gems/activesupport-7.0.4/yardoc
[INFO] Loading activesupport 7.0.4 from cache
[INFO] Loading builder 3.2.4 from cache
[INFO] Loading erubi 1.12.0 from cache
[INFO] Loading racc 1.6.2 from cache
[INFO] Loading nokogiri 1.13.10 from cache
[INFO] Loading rails-dom-testing 2.0.3 from cache
[INFO] Loading crass 1.0.6 from cache
[INFO] Loading loofah 2.19.1 from cache
[INFO] Loading rails-html-sanitizer 1.4.4 from cache
[INFO] Using cached documentation for actionview at /home/ali/.solargraph/cache/gems/actionview-7.0.4/yardoc
[INFO] Loading actionview 7.0.4 from cache
[INFO] Loading rack 2.2.5 from cache
[INFO] Loading rack-test 2.0.2 from cache
[INFO] Using cached documentation for actionpack at /home/ali/.solargraph/cache/gems/actionpack-7.0.4/yardoc
[INFO] Loading actionpack 7.0.4 from cache
[INFO] Loading nio4r 2.5.8 from cache
[INFO] Loading websocket-extensions 0.1.5 from cache
[INFO] Loading websocket-driver 0.7.5 from cache
[INFO] Using cached documentation for actioncable at /home/ali/.solargraph/cache/gems/actioncable-7.0.4/yardoc
[INFO] Loading actioncable 7.0.4 from cache
[INFO] Loading globalid 1.0.0 from cache
[INFO] Using cached documentation for activejob at /home/ali/.solargraph/cache/gems/activejob-7.0.4/yardoc
[INFO] Loading activejob 7.0.4 from cache
[INFO] Using cached documentation for activemodel at /home/ali/.solargraph/cache/gems/activemodel-7.0.4/yardoc
[INFO] Loading activemodel 7.0.4 from cache
[INFO] Using cached documentation for activerecord at /home/ali/.solargraph/cache/gems/activerecord-7.0.4/yardoc
[INFO] Loading activerecord 7.0.4 from cache
[INFO] Loading marcel 1.0.2 from cache
[INFO] Loading mini_mime 1.1.2 from cache
[INFO] Using cached documentation for activestorage at /home/ali/.solargraph/cache/gems/activestorage-7.0.4/yardoc
[INFO] Loading activestorage 7.0.4 from cache
[INFO] Loading date 3.3.3 from cache
[INFO] Loading timeout 0.3.1 from cache
[INFO] Loading net-protocol 0.2.1 from cache
[INFO] Loading net-imap 0.3.4 from cache
[INFO] Loading net-pop 0.1.2 from cache
[INFO] Loading net-smtp 0.3.3 from cache
[INFO] Loading mail 2.8.0 from cache
[INFO] Using cached documentation for actionmailbox at /home/ali/.solargraph/cache/gems/actionmailbox-7.0.4/yardoc
[INFO] Loading actionmailbox 7.0.4 from cache
[INFO] Using cached documentation for actionmailer at /home/ali/.solargraph/cache/gems/actionmailer-7.0.4/yardoc
[INFO] Loading actionmailer 7.0.4 from cache
[INFO] Using cached documentation for actiontext at /home/ali/.solargraph/cache/gems/actiontext-7.0.4/yardoc
[INFO] Loading actiontext 7.0.4 from cache
[INFO] Loading method_source 1.0.0 from cache
[INFO] Loading thor 1.2.1 from cache
[INFO] Loading zeitwerk 2.6.6 from cache
[INFO] Using cached documentation for railties at /home/ali/.solargraph/cache/gems/railties-7.0.4/yardoc
[INFO] Loading railties 7.0.4 from cache
[INFO] Loading active_storage_validations 0.8.9 from cache
[INFO] Loading execjs 2.8.1 from cache
[INFO] Loading autoprefixer-rails 10.4.7.0 from cache
[INFO] Loading bcrypt 3.1.18 from cache
[INFO] Loading ffi 1.15.5 from cache
[INFO] Loading sassc 2.4.0 from cache
[INFO] Loading bootstrap-sass 3.4.1 from cache
[INFO] Loading will_paginate 3.1.8 from cache
[INFO] Loading bootstrap-will_paginate 1.0.0 from cache
[INFO] Loading faker 2.1.2 from cache
[INFO] Loading mini_magick 4.9.5 from cache
[INFO] Loading ruby-vips 2.1.4 from cache
[INFO] Loading image_processing 1.9.3 from cache
[INFO] Loading importmap-rails 1.1.5 from cache
[INFO] Loading jbuilder 2.11.5 from cache
[INFO] Loading uri 0.12.0 from cache
[INFO] Loading net-http 0.3.2 from cache
[INFO] Loading puma 5.6.5 from cache
[INFO] Loading sprockets 4.2.0 from cache
[INFO] Loading sprockets-rails 3.4.2 from cache
[INFO] Loading stimulus-rails 1.2.1 from cache
[INFO] Loading turbo-rails 1.3.2 from cache
Ruby version: 3.1.3
Solargraph version: 0.48.0
Solargraph Rails version: 1.1.0

@ali-p-q
Copy link
Author

ali-p-q commented Dec 31, 2022

In case someone wants to add all methods from ActiveModel and Ruby's standard class, here is the file I am using:
definition.rb

@grncdr
Copy link
Collaborator

grncdr commented May 11, 2023

This is an interesting one, as Rails source code doesn't really magically load standard lib dependencies. It contains explicit requires (e.g. require 'securerandom' in activesupport).

This might be a solargraph issue, because I'd sort of expect it to find require calls in gems, but I'm honestly not 100% sure if that's expected behaviour. I'd like to ask over there first before we commit ourselves to tracking every require in Rails here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants