solargraph-rails icon indicating copy to clipboard operation
solargraph-rails copied to clipboard

undefined method `present?' for "":String

Open mintuhouse opened this issue 1 year ago • 8 comments

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?

mintuhouse avatar Sep 29 '23 07:09 mintuhouse

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'

RyanVerhey avatar Oct 23 '23 17:10 RyanVerhey

I am getting the same issue as well.

alexrecuenco avatar Oct 26 '23 13:10 alexrecuenco

@iftheshoefritz any updates on this?

borisrorsvort avatar Nov 28 '23 13:11 borisrorsvort

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?

xinyifly avatar Dec 22 '23 02:12 xinyifly

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")

mintuhouse avatar Dec 22 '23 03:12 mintuhouse

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 avatar Jan 16 '24 00:01 masamitsu-murase

Seem this is still an issue

jcarlos7121 avatar Jul 03 '24 20:07 jcarlos7121

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
}

marcosmcz avatar Jul 09 '24 17:07 marcosmcz