Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

Rails: Support Auto-Completion in Web Console (Ruby::GSoC2016)




I have added the "Auto-Completion" feature to help typing commands on Web Console. For example, if people type the TAB key when typing the prefix of some commands, then it shows the list of possible commands from the prefix.

GIF of auto-completion


The auto-suggests mode using the auto-completing functions in order to help us typing commands. It starts the auto-completion automatically after the 3rd character press, it will hint the "proper" one.



Here are links to commits in this summer (and see also here).

81dccc2: Use Thread.current for exception on View class

It broke the View#only_on_error_page method.

fa6792a: Render a script tag with its file name

It allows us to select the script tag on testing.

af2ac1a: Add a test for rendering error_page.js

ad5e3ab: Edit .travis.yml

  • Remove "Gemfile" from allow_failures because all build jobs were allowed to fail
  • Update ruby from "2.2.3" to "2.2.5" and use "2.3.1".
  • No wait jobs are allowed to fail by "fast_finish"
  • Run test:templates

acfa1db: Let FakeMiddleware to load "lib/web_console.rb"

On testing templates, the FakeMiddleware caused an error when the "WebConsole.looger" is missing, so we couldn't run tests for templates.

Previously, the "lib/web_console.rb" required all modules, and it caused some troubles on the middleware, but now it is using ActiveSupport::Autoload, so we don't worry about the troubles and the middleware can require it.

e8f0f7b: Find a initial binding for each session

831fbed: Add test for initial binding of session

37be341: Fix test for middleware

We should pass a binding or bindings to the

35a1aca: Reset Thread.current for each test on middleware's tests

ee261ba: Use first binding when there is no application binding

If an error happens inside the framework before loading application, the ActionDispatch::ExceptionWrapper shows traces for the framework only. It could be outside of "Rails.root", and so we have to fallback to the first one.

62b7332: Add test for initial binding

d42d509: Add Session#context(obj) method

7356115: Add Autocomplete class to console.js

c5a90d5: Let's use auto completion on console by TAB key

7cc76ad: Test auto completion feature

2be719d: WIP: Enhance template testing

77d6f67: Rename test_templates.rake => templates.rake

f5fdfc4: Use non-nested tasks for templates

12e9228: Enhance rake tasks for templates

ce38d74: Unify template tests into one style

8fb1ee4: Test key events for auto-completion

1cc1a3e: Remove duplicated words in auto completing

3002c7b: Remove unused test helpers for templates testing

43a5a9d: Do nothing if no words is passed to Autocomplete

a382ab8: Add Autocomplete#trim method

1244ded: Trim suggestions for auto-completion to show them in a few line

d3b9629: Move refining tests for auto-completion into a test suite

a02fbc2: Test trimming for auto-completion

a0df0f1: Support for RAILS_RELATIVE_ROOT

If the RAILS_RELATIVE_ROOT is set, Web Console could be missing its end-point, and it could return 404 error.

// An example case

map '/relative/root' do
  run MyApp
$ RAILS_RELATIVE_URL_ROOT=/relative/root bundle exec rails s

In order to fix this, the initializer of the Middleware.mount_point inserts the relative root before the mount point if the configuration is set.

943f77e: Add tests for "config.web_console.mount_point"

7030c32: Drop Array#flatten from the Context class

aa541b1: Add REPLConsole#contextRequest to send context request

ef24674: Support to flatten context on frontend and sort items by priority

f3ea3e7: Add hinting area for the suggest-mode on the frontend

377f5a3: Start auto-completion by pressing "Ctrl-E"

And stop it if the input is empty after deleting characters.

Idea by @gsamokovarov


  • Improve auto-completions and auto-suggestions
    • I think that we can improve its output more user-friendly
  • Find a way for extending web-console
    • I want to work on it after this summer

Thank you :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.