Add links in exception page to open Application Trace file to line in VSCode. Now only support VSCode or VSCodium.
- Show VSCode icons
- Click to open vscode/vscodium
- Open file to line
- Custom Settings and Full Trace
- Display URLs in console/log files
- Per browser settings in localStorage
Add following to your Rails Gemfile
:
group :development do
gem 'open_code-rails'
end
VSCode supports Opening VS Code with URLs.
This gem simply inject some CSS and JS to HTML response while status is 500. Your browser will parse DOM and generate new links.
You should put settings in config/environments/development.rb
because this gem should only work in dev server. It will prevent production server starting up.
-
config.open_code.editor
- default:'vscode'
Currently only support
'vscode'
and'vscodium'
. It will be used to link's scheme part, likevscode://
orvscodium://
. You can set it any string but probably won't work, unless your editor supports<scheme>://file/<absolute file path>
.Set to
false
,'off'
or'disabled'
to disable this gem# config/environments/development.rb Rails.application.configure do config.open_code.editor = 'vscodium' end
-
config.open_code.place_holder
- default:''
(blank)Leave it blank will display links as VSCode icon. If you set it to a string, it will display text rather than icon. In case your browser does not support SVG Data URI in CSS, or you don't like the icon.
# config/environments/development.rb Rails.application.configure do config.open_code.place_holder = 'Open in VSCodium' end
-
config.open_code.root_dir
- default:::Rails.root
The absolute path of your Rails project folder. Sometimes you may run dev server remotely, so you need to set it to your local path.
# config/environments/development.rb Rails.application.configure do config.open_code.editor = '/Users/MyName/projects' end
-
config.open_code.logger_url
- default:false
Display VSCode/VSCodium urls rather than relative filenames in Rails Logger. So you should see URLs in dev mode console and
development.log
.This option directly replaces the results of
::Rails.backtrace_cleaner.clean
.
Some flexibility is probably required for cooperation. Different people may have various preferences of IDE/editors, also the folder could be placed differently. So here you go.
-
FORCE_OPEN_CODE_EDITOR
When is not blank,
config.open_code.editor
will be overridden.Set to
false
,off
ordisabled
to disable the gem$ /usr/bin/env FORCE_OPEN_CODE_EDITOR=off rails s
-
FORCE_OPEN_CODE_PLACE_HOLDER
When is not blank,
config.open_code.place_holder
will be overridden.$ /usr/bin/env FORCE_OPEN_CODE_PLACE_HOLDER='Open in VSCodium' rails s
-
FORCE_OPEN_CODE_ROOT_DIR
When is not blank,
config.open_code.root_dir
will be overridden.$ /usr/bin/env FORCE_OPEN_CODE_ROOT_DIR='/my/project/path' rails s
-
FORCE_OPEN_CODE_LOGGER_URL
When is not blank,
config.open_code.logger_url
will be overridden.Set to
false
,off
ordisabled
to disable this functionality. Blank value will be ignored. All other values will enable this functionality.$ /usr/bin/env FORCE_OPEN_CODE_LOGGER_URL=on rails s
This functionality requires localStorage.
-
_openCode.settings()
Should return keys below
-
disabled
-
iconUrl or placeHolder - you can only have one at the same time.
-
rootDir
-
scheme - same as
config.open_code.editor
-
linkBuilder - a function to build
href
. Default builder:function (scheme, rootDir, path, line) { return scheme + '://file/' + encodeURI(rootDir + '/' + path + ':' + line); }
-
-
_openCode.getValue(key)
Get individual value by given key.
-
_openCode.setValue(key, value)
Set individual value by given key.
-
_openCode.reset()
Reset all settings - back to default.
Changing this settings only applies to the current browser. It does not have any impacts to Rails app.