Giter Site home page Giter Site logo

Comments (11)

dgutov avatar dgutov commented on June 6, 2024

Hi!

Am I reading that right that it's trying to visit a file with a newline at the end? Or is that just a side-effect of copying?

from robe.

dgutov avatar dgutov commented on June 6, 2024

Does that file contain any methods? If not:

Check the contents of $LOADED_FEATURES in the REPL. Does the file name there look right?

If you like, you can try print-debugging the full_scan method, it should be triggered in this scenario: https://github.com/dgutov/robe/blob/master/lib/robe/sash/const_locations.rb#L56-L69

Or you can try producing a minimal reproduction: a sample project which has this problem. And I'll take it from there.

from robe.

sun0f3 avatar sun0f3 commented on June 6, 2024

i made a video with the issue https://youtu.be/R_q7MIx93iM, i've checked $LOADED_FEATURES

from robe.

dgutov avatar dgutov commented on June 6, 2024

Hi again!

Sorry for the late reply.

You examine the value of $LOADED_FEATURES near the beginning of the video, and it doesn't have the files in question. But Rails has an autoloading feature: when you access a constant (and module names are constants), the autoloader (most recently, Zeitwerk) can look up existing files in the specified list of directories. So at the end of the scenario the value of this constant should be longer.

But now that I read it again, I see that full_scan checks that the feature ends with .rb anyway, so it's unlikely that the problem came from that method.

Here's my next guess: one of the methods on Api::V1::Firm::Members::IndexSerializer (and ShowSerializer as well, apparently) returns such broken value in its source_location method.

Try this snippet in the created inf-ruby Rails console with Robe loaded:

obj = Api::V1::Firm::Members::IndexSerializer

methods = obj.methods(false).map { |m| obj.method(m) } +
          (obj.__instance_methods__(false) +
           obj.private_instance_methods(false)).map { |m| obj.instance_method(m) }

methods.each { |m| puts "#{m}: #{m.source_location&.first}" }

from robe.

mrrooijen avatar mrrooijen commented on June 6, 2024

I just ran into this issue as well. Most files would properly open using robe-jump but certain files would not.

Considering the fact that similar files (i.e. other models) do appear to open, I figured that perhaps the problem was with the contents of the file. It turns out that this is the case.

The following file will not open with robe-jump.

class User::CreateInput
end

Error (similar to @99monkey):

'/Users/michael/dev/poc/app/inputs/user/create_input.rb
' does not exist

But the same file containing a single method definition will open as expected:

class User::CreateInput
  def this_method_definition_fixes_the_problem
  end
end

The same applies to the model file.

class Team < ApplicationRecord
  has_many :memberships
  validates :name, presence: true
  # etc
end

Here we have a bunch of class method calls, but no method definitions.

When attempting to open this file using robe-jump the following error occurs:

'/Users/michael/.gem/rubv/3.1.2/gems/rubocop-1.35.1/lib/rubocop/cop/team.rb
/Users/michael/.gem/ruby/3.1.2/gems/faker-2.23.0/lib/faker/default/team.rb
/Users/michael/dev/poc/app/models/team.rb
'does not exist

I want to open app/models/team.rb but it finds three different paths and doesn't open anything.

However, after adding a method definition it appears to work correctly.

class Team < ApplicationRecord
  has_many :memberships
  validates :name, presence: true
  # etc
  def this_method_definition_fixes_the_problem
  end
end

Defining a class method instead of an instance method also fixes the problem (def self. this_method_definition_fixes_the_problem).

Thoughts?

from robe.

sun0f3 avatar sun0f3 commented on June 6, 2024

Yes, it's my case too, I guess. Serializer in most cases dont have definition of methods. I should check this out..

from robe.

dgutov avatar dgutov commented on June 6, 2024

If this happens only when the class has no methods of its own, then...

Could you try changing this line in your local installation

if status.exitstatus == 127

to if false (and maybe commenting out the previous line as well), as see if that fixes the behavior?

from robe.

dgutov avatar dgutov commented on June 6, 2024

Aaand never mind, this should fix that. Apparently BSD Grep assigns different meaning to -Z.

Let me know if the problem remains, of course.

from robe.

mrrooijen avatar mrrooijen commented on June 6, 2024

Yep, that fixed the issue. Thanks!

Is there a way to limit robe-jump results to the current project?

robe-jump on Team yields the following, and then you can just select the desired file:

.gem/ruby/3.1.2/gems/rubocop-1.35.1/lib/rubocop/cop/team.rb
.gem/ruby/3.1.2/gems/faker-3.0.0/lib/faker/default/team.rb
dev/poc/app/models/team.rb

Not a big deal, but would be nice if it could just assume app/models/team.rb rather than the other results.

Thanks for the great package.

from robe.

dgutov avatar dgutov commented on June 6, 2024

Are you sure to want to limit it to the current project?

One of the benefits of this package is that it can navigate to gems (Solargraph has more difficulties with that). And it's handy to be able to see an implementation of some library feature from time to time.

What we could try to do though, is to sort the locations during completion so that those inside the project come first.

from robe.

dgutov avatar dgutov commented on June 6, 2024

There's also the issue that in the other two suggestions the fully-qualified name is longer than Team, so preprocessing those based on the file contents could work as well.

Anyway, please open a separate issue and we'll continue there.

from robe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.