castwide / vscode-solargraph

A Visual Studio Code extension for Solargraph.
Other
425 stars 23 forks source link

Workspace symbols not working with class_eval #223

Open shankar15498 opened 3 years ago

shankar15498 commented 3 years ago

foo.rb

class Foo
  def bar
    puts "hi"
  end
end

foo_decorator.rb

Foo.class_eval do
  def baz
    puts "hi"
  end
end

In vscode, if I hit ctrl + p and search for #bar am able to find the bar method but #baz is not finding the baz method.

VSCode Version: 1.56.2 solargraph gem version: 0.41.2 ruby version: ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]

Thanks in advance

shankar15498 commented 3 years ago

The issue is somewhat fixed right now.

I read on a rubylocate GitHub issue that the "Go to definition" will not work properly in workspaces with multiple folders. So I removed one of the folders from the workspace and solargraph started working as expected. So I can manage for now.

It would be nice to have multi folder workspace support for workspace symbols :)

castwide commented 3 years ago

The problem here was an old limitation in how Solargraph maps class and method definitions. Switching the definition's namespace dynamically with a class_eval method wasn't possible, but recent changes to the mapper might change that. Updates to that feature are being tracked in castwide/solargraph#487.

Symbols spanning multiple workspaces are a different issue. They're treated as discrete libraries by default, which is sometimes but not always the desired behavior. I'm working on a mechanism to make workspaces visible to each other.