Add link to external editor to rescue view #46378
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a somewhat trivial diff. Currently, when an exception is thrown, a page is rendered and part of the page has the paths and line numbers from the exception stack. The lines are clickable and when clicked, the upper section changes to show more context of the line in the original source code.
The proposed change is to add an additional link whose text is the Unicode link symbol after the existing link. The more common glyph was rejected by Unicode.
The href for the link symbol comes from Ruby code that first checks, at render time, to see if ActionDispatch::DebugView#ext_editor is defined. If it is, it is called passing the "frame". Otherwise, ActionDispatch::DebugView#int_editor is called.
int_editor creates a URL using the
file:
scheme. While most browsers won't follow the link, it will show to the developer what is possible. My example of ext_editor creates a URL using theemacs:
scheme.I've added a tool tip to try and tell the developers how they can configure the URL to invoke their favorite editor.
I thought the approach of checking to see if a method is defined and calling it would be preferred to having the user redefine the definition of an existing method.
Another piece of work to do would be to add something like the sample I have to the templates so that config/initializers/debug_view.rb would be created when the Rails app is created.
Having both links, the currently existing link that shows the code snippets and the new link that opens the file in the external editor, gives the users the best of both worlds. They can view in the browser what happened and then click to get them placed in their favorite editor at the line number for the issue.
The key here is "their favorite editor" can be customized to their liking via the ext_editor method.
Motivation / Background
This Pull Request has been created because adding a link to the exception rescue page to the files and lines that are in the exception stack will help the developer edit the area that caused the fault.
Detail
This Pull Request changes:
M actionpack/lib/action_dispatch.rb
M actionpack/lib/action_dispatch/middleware/debug_view.rb
M actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
A actionpack/lib/action_dispatch/locale/en.yml
Additional information
My example for what a developer can add to config/initializers/debug_view.rb: