-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add jump to view code lenses #412
Conversation
1a7e37d
to
5356284
Compare
def add_jump_to_view(node) | ||
class_name, _ = T.must(@constant_name_stack.last) | ||
action_name = node.name | ||
controller_name = class_name.delete_suffix("Controller").gsub(/([a-z])([A-Z])/, "\\1_\\2").downcase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the intention behind the gsub
here, can you explain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh, now I see, it's to find the individual words, since that's where there's a change in case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(is this copied straight from Rails?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I wrote it myself. It's turning the controller name into the directory path.
action_name = node.name | ||
controller_name = class_name.delete_suffix("Controller").gsub(/([a-z])([A-Z])/, "\\1_\\2").downcase | ||
|
||
view_uris = Dir.glob("#{@client.rails_root}/app/views/#{controller_name}/#{action_name}*").map! do |path| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could get this programatically:
irb(main):004> UsersController.view_paths.map(&:path)
=> ["/Users/andyw8/src/github.com/Shopify/ruby-lsp-rails/test/dummy/app/views"]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(would require a little more plumbing for the server request of course)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like that method is returning what we want though. It's returning the views
directory, but not the directory for the UsersController
views. Is there a way to make it return it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried but couldn't find an obvious way.
5356284
to
3256ff4
Compare
Closes #384
This PR adds the ability to jump to related views from a controller action.
Implementation:
ruby-lsp
just to get proper ERB supportRails.root
from the server initialization response. We often need to know where the application exists from the addon sideScreen.Recording.2024-07-17.at.9.57.46.AM.mov