iftheshoefritz / solargraph-rails

Solargraph plugin to add awareness of Rails-specific code
MIT License
323 stars 30 forks source link

undefined method `present?' for "":String #60

Open mintuhouse opened 1 year ago

mintuhouse commented 1 year ago

Getting below error and dont see schema.rb columns in suggestions when I start solargraph with bundle

[WARN] undefined method `present?' for "":String
/bundle/ruby/3.2.0/gems/solargraph-rails-1.1.0/lib/solargraph/rails/schema.rb:90:in `infer_table_names'
/bundle/ruby/3.2.0/gems/solargraph-rails-1.1.0/lib/solargraph/rails/schema.rb:85:in `find_table'
/bundle/ruby/3.2.0/gems/solargraph-rails-1.1.0/lib/solargraph/rails/schema.rb:41:in `process'
/bundle/ruby/3.2.0/gems/solargraph-rails-1.1.0/lib/solargraph-rails.rb:45:in `block in local'
/bundle/ruby/3.2.0/gems/solargraph-rails-1.1.0/lib/solargraph-rails.rb:60:in `run_feature'
/bundle/ruby/3.2.0/gems/solargraph-rails-1.1.0/lib/solargraph-rails.rb:45:in `local'
/bundle/ruby/3.2.0/gems/solargraph-0.49.0/lib/solargraph/convention.rb:29:in `block in for_local'

Could it be because active_support is not loaded?

RyanVerhey commented 1 year ago

I am having the same issue, although from line 89:

[WARN] undefined method `present?' for "MyClassName":String
Did you mean?  prepend
/Users/ryan/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/solargraph-rails-1.1.0/lib/solargraph/rails/schema.rb:89:in `infer_table_names'
/Users/ryan/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/solargraph-rails-1.1.0/lib/solargraph/rails/schema.rb:84:in `find_table'
/Users/ryan/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/solargraph-rails-1.1.0/lib/solargraph/rails/schema.rb:41:in `process'
/Users/ryan/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/solargraph-rails-1.1.0/lib/solargraph-rails.rb:45:in `block in local'
/Users/ryan/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/solargraph-rails-1.1.0/lib/solargraph-rails.rb:60:in `run_feature'
/Users/ryan/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/solargraph-rails-1.1.0/lib/solargraph-rails.rb:45:in `local'
/Users/ryan/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/solargraph-0.49.0/lib/solargraph/convention.rb:29:in `block in for_local'
alexrecuenco commented 1 year ago

I am getting the same issue as well.

borisrorsvort commented 11 months ago

@iftheshoefritz any updates on this?

xinyifly commented 10 months ago

I got this error after upgraded to Rails 7.1.2 from 7.0.6 (or maybe other dependencies in my Gemfile) Which caused schema.rb not working properly. Any workaround yet?

mintuhouse commented 10 months ago

For others facing this issue, i have resolved it in my codebase by generating a binstub for solargraph and configuring vscode to use bin/solargraph as its path

In this binstub I load active_support explicitly before calling original executable for solargraph

#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'solargraph' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
  if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
    load(bundle_binstub)
  else
    abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
  end
end

require "rubygems"
require "bundler/setup"

# Detect problems if any using `solargraph scan`
require "active_support/all" # Fix for https://github.com/iftheshoefritz/solargraph-rails/issues/60
require "solargraph/rails/schema" # Fix for https://github.com/iftheshoefritz/solargraph-rails/issues/61
Solargraph::Rails::Schema::RUBY_TYPES[:enum] = "String"

load Gem.bin_path("solargraph", "solargraph")
masamitsu-murase commented 10 months ago

I also created a temporary patch for this issue as a gem library, solargraph-rails-patch-for-rails71. With this gem library, we don't face this error even if we use Rails 7.1.

Please install this gem and update .solargraph.yml as follows:

plugins:
- solargraph-rails
- solargraph-rails-patch-for-rails71  # Add this line
jcarlos7121 commented 4 months ago

Seem this is still an issue

marcosmcz commented 4 months ago

I also created a temporary patch for this issue as a gem library, solargraph-rails-patch-for-rails71. With this gem library, we don't face this error even if we use Rails 7.1.

Please install this gem and update .solargraph.yml as follows:

plugins:
- solargraph-rails
- solargraph-rails-patch-for-rails71  # Add this line

@masamitsu-murase Life saver!!!! This fixed it for me! Thank you so much!

For future readers using Vim: I'm using solargraph-rails with the coc.nvim LSP in Vim. I'm using the coc-solargraph LSP, along with these gems, on OSX, with Rails 7.1.3, ruby 3.2.2 This is my CocConfig

{
  "solargraph.commandPath": "/Users/<username>/.rbenv/shims/solargraph",
  "solargraph.useBundler": false
}