Create autocompletion dropdown for Cucumber paths in Textmate

Updated . Posted . Visible to the public.

Ever wanted autocompletion for paths from paths.rb in Cucumber? This card lets you write your steps like this:

When I go to path *press tab now* # path is replaced with a list of all known Cucumber paths

This is how you do it

(key shortcuts apply for TextMate2)

  1. Open the bundle editor (ctrl + alt +  + B)

  2. Create a new Item ( + N), select "Command"

  3. Paste this:
    ^
    #!/usr/bin/env ruby -wKU
    require File.join(ENV['TM_SUPPORT_PATH'], 'lib', 'ui.rb')

    cucumber_paths = File.join ENV['TM_PROJECT_DIRECTORY'], 'features', 'support', 'paths.rb'
    if File.exist? cucumber_paths
    lines = []
    File.open(cucumber_paths, 'r').each do |line|
    lines << line.slice(/\s+when /^?([^$]*)$?/[im]?$/, 1) # @param 1: return first matched group
    end
    paths = lines.compact.sort

    TextMate::UI.complete(paths, :extra_chars => " ")
    else
    %x{ "$DIALOG" tooltip --html 'File /features/support/paths.rb not found.' }
    end

Now you only need some more configuration:

  • Name the command (e.g. "Cucumber: paths")
  • scope selector is text.gherkin.feature
  • choose a tab trigger (e.g. "path")
  • input: nothing
  • output: insert at caret
  • caret placement: after output

You're done!

Dominik Schöler
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2012-09-17 06:25)