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

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

Open
mintuhouse opened this issue Sep 29, 2023 · 8 comments
Open

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

mintuhouse opened this issue Sep 29, 2023 · 8 comments

Comments

@mintuhouse
Copy link

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
Copy link

RyanVerhey commented Oct 23, 2023

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
Copy link

I am getting the same issue as well.

@borisrorsvort
Copy link

@iftheshoefritz any updates on this?

@xinyifly
Copy link

xinyifly commented Dec 22, 2023

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
Copy link
Author

mintuhouse commented Dec 22, 2023

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
Copy link
Contributor

masamitsu-murase commented Jan 16, 2024

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
Copy link

Seem this is still an issue

@marcosmcz
Copy link

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
}

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

8 participants