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

Cannot jump to a namespaced definition

Open Intrepidd opened this issue 5 years ago • 8 comments

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 avatar Nov 19 '20 09:11 Intrepidd

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

Intrepidd avatar Nov 19 '20 09:11 Intrepidd

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

castwide avatar Dec 14 '20 18:12 castwide

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

Intrepidd avatar Dec 14 '20 20:12 Intrepidd

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.

castwide avatar Dec 14 '20 20:12 castwide

@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.

sultanahamer avatar Mar 03 '22 05:03 sultanahamer

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

stathis-alexander avatar Jun 06 '22 13:06 stathis-alexander

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

timolehto avatar Jun 09 '22 06:06 timolehto

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

buraga-dmitrii avatar Jul 10 '23 17:07 buraga-dmitrii