castwide / vscode-solargraph

A Visual Studio Code extension for Solargraph.
Other
423 stars 25 forks source link

Cannot jump to a namespaced definition #200

Open Intrepidd opened 3 years ago

Intrepidd commented 3 years ago

Jumping to a class works fine, however it won't work if the class is within a namespace :

Screenshot 2020-11-19 at 10 31 33

However, the definitions are visible within the symbols : Screenshot 2020-11-19 at 10 31 56

Intrepidd commented 3 years ago

it looks like it works if I write he name-spaced class like this :

module Bar
  class Baz
  end
end

Could we make it work for the class Bar::Baz format as well ? Happy to help if you give me pointers on how to implement it

castwide commented 3 years ago

Definition works with nested namespaces as long as all the namespaces are defined. Example:

class Foo
end

module Bar
end

class Bar::Baz
end

Bar::Baz # <- Definition of `Baz` works

I'm not sure if this behavior should be changed, since it accurately reflects runtime behavior. Running the following code results in a NameError:

class Foo
end

class Bar::Baz # <- uninitialized constant Bar (NameError)
end
Intrepidd commented 3 years ago

With rails and the Zeitwerk loader modules can be defined on the fly

However for several reasons I decided to not write my modules this way anymore, so I no longer require this feature.

Feel free to close if you choose not to go this way :)

castwide commented 3 years ago

Understood. That seems like a good candidate for an optional feature, or possibly a separate extension.

I'll keep this open at least until I create a new issue for the implementation.

sultanahamer commented 2 years ago

@castwide I am facing the same issue on a rails project. Do let me know in what would this take to implement.

I can try from my side on code and testing.

stathis-alexander commented 2 years ago

We use inline class definitions (without prior module definitions) in our projects as well. Having this feature would be incredibly useful.

timolehto commented 2 years ago

This bit us as well. Some sort of Zeitwerk support would be super. Now we need to remember to add these "old school" empty namespace module definition files all over just for this. E.g.:

$ cat packages/core.rb
module Core
end
buraga-dmitrii commented 1 year ago

We have the same style in rails projects. We need this feature too. Have some issue opened for this feature?