Code Completion for Gherkin - help shape the spec!

511 views
Skip to first unread message

aslak hellesoy

unread,
Apr 20, 2011, 3:14:28 AM4/20/11
to Cucumber Users, spec...@googlegroups.com, ever...@gmail.com, kevin....@gmail.com
Hi folks (cc'ed SpecFlow/Cuke4PHP/Behat guys)

Editor code completion is a sorely needed feature for anyone working with Gherkin documents. I have started on a spec for this: https://github.com/aslakhellesoy/gherkin/wiki/Code-Completion
I'd love feedback from:

* People working on editor support for Gherkin/Cucumber
* People working on Cucumber clones
* Users with strong opinions on the subject

Please respond to this thread (on cu...@googlegroups.com) or comment directly in the wiki page.
Personally I'll be working on code completion support in the Ace editor - you can already see an embryonic demo here: http://cukes.info/trycuke/ (I have a local version with syntax highlighting).

Cheers,
Aslak

Gáspár Nagy

unread,
Apr 20, 2011, 5:11:56 AM4/20/11
to Cukes
Hi,

I'm fully supporting the idea, as discussed at CukeUp and I have also
started to think about this (actually started to wrap it up as an
article). I have created a diagram showing the important aspects of
the steps in a Gherkin project (from SpecFlow's point of view, but I
hope the picture fits to Cucumber and the other tools too). It's here:
http://dl.dropbox.com/u/51289/BlogAttachments/StepMap.pdf (uses
slightly different namings)

It is another question how much part of this is really necessary for
the completion. I think the best would be to have a basic set that
every tool supports and allow extension points where specialties of
the tools could be stored, in case the editor wants to support them
(eg. in SpecFlow you can scope the step definitions). The alternative
is that every tool manages it's own format, but can expert to the
common format. I'm fine with both.

For this basic feature set, in addition to Aslak's proposal, I can
think of:
- handling steps in scenario outlines (shall we display the steps with
the <parameters> or the expanded ones - the ones with the param will
not necessarily match the regex)
- displaying "unbound" steps
- storing also the table / multiline text argument of the text as
well, or at least a sample of it (e.g. table header)

Other comments:

I don't exactly know how it is with Cucumber, but SpecFlow also
considers the argument transformations when deciding if a step
matches. While I'm sure we don't want to include that in the
completion, we have to be prepared that one step can also match to
multiple step definitions, which complicates the things a little bit.

If we have the exactly the same step (with the same params) used in
the feature files, we should display it in the completion list only
once.

Incremental update: for this we need to store the "origin" of the step
definitions and the step instances, otherwise you cannot remove the
old entries in case of a change.

For the storage format, my vote is for JSON as it is much easier to
use it any platform (e.g. in .NET there is an x64 and an x86 version
of SQLite provider which is an extra maintenance issue). Also better
fits to hierarchical data than RDBMS.

Br,
Gaspar

Konstantin Kudryashov

unread,
Apr 20, 2011, 10:12:48 PM4/20/11
to cu...@googlegroups.com
I'm in! How can i help?

--------------------------------------------------
Konstantin Kudryashov (everzet)


Andrew Premdas

unread,
Apr 21, 2011, 7:25:28 AM4/21/11
to cu...@googlegroups.com
On 20 April 2011 08:14, aslak hellesoy <aslak.h...@gmail.com> wrote:
Hi folks (cc'ed SpecFlow/Cuke4PHP/Behat guys)

Editor code completion is a sorely needed feature for anyone working with Gherkin documents. I have started on a spec for this: https://github.com/aslakhellesoy/gherkin/wiki/Code-Completion
I'd love feedback from:


Could you expand a bit on what you mean. In particular:

- does the current textmate bundle do 'editor code completion' with its snippets
- do you foresee some sort of java like code completion where typing dot prompts a list of choices. If so could you give an example
- is there anything the texmate bundle should do but doesn't do

I'd be happy to contribute ideas. But currently I think the textmate bundle does enough for me, so I'm trying to get a feel for what more could be done

Cheers

Andrew




* People working on editor support for Gherkin/Cucumber
* People working on Cucumber clones
* Users with strong opinions on the subject

Please respond to this thread (on cu...@googlegroups.com) or comment directly in the wiki page.
Personally I'll be working on code completion support in the Ace editor - you can already see an embryonic demo here: http://cukes.info/trycuke/ (I have a local version with syntax highlighting).

Cheers,
Aslak

--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cu...@googlegroups.com.
To unsubscribe from this group, send email to cukes+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.



--
------------------------
Andrew Premdas

aslak hellesoy

unread,
Apr 21, 2011, 10:39:51 AM4/21/11
to cu...@googlegroups.com
On Thu, Apr 21, 2011 at 3:12 AM, Konstantin Kudryashov <ever...@gmail.com> wrote:
I'm in! How can i help?


By improving one of the editors you use (or would like to use) I guess. How about helping me implement a Gherkin editor based on Ace? (http://ace.ajax.org/)

Here is my vision:
* A small node.js app based on express and dust for templates (I have started on that)
* Bundle with a i18n syntax highlighter for Gherkin (I have started on that too)
* Start implementing code-completion in Ace
* Reads and writes files using WebDav and/or REST: https://github.com/mikedeboer/jsdav

Ace doesn't have a code completion module (google ace code completion), but building it on top with pure dom/jQuery should't be too hard. Writing some real code will also help shape the code completion spec.

I'm going to be away for 10 days, but I'll get back with more (and share my code) when I'm back. Are these technologies something you'd be able to work with? Did you have anything else in mind?

aslak hellesoy

unread,
Apr 21, 2011, 10:44:39 AM4/21/11
to cu...@googlegroups.com
On Thu, Apr 21, 2011 at 12:25 PM, Andrew Premdas <apre...@gmail.com> wrote:


On 20 April 2011 08:14, aslak hellesoy <aslak.h...@gmail.com> wrote:
Hi folks (cc'ed SpecFlow/Cuke4PHP/Behat guys)

Editor code completion is a sorely needed feature for anyone working with Gherkin documents. I have started on a spec for this: https://github.com/aslakhellesoy/gherkin/wiki/Code-Completion
I'd love feedback from:


Could you expand a bit on what you mean. In particular:

- does the current textmate bundle do 'editor code completion' with its snippets

I'm not sure what it does - I haven't used it for ages
 
- do you foresee some sort of java like code completion where typing dot prompts a list of choices. If so could you give an example

Yes, something like that. Type Given[SPACE] and it will show a popup that changes as you type. I tried to explain it in the wiki under "Desired editor behaviour"
 
- is there anything the texmate bundle should do but doesn't do


Again, I don't know, but I assume it doesn't show examples from other scenarios?
 
I'd be happy to contribute ideas. But currently I think the textmate bundle does enough for me, so I'm trying to get a feel for what more could be done


That's good to hear - keep ideas coming!
It would be nice if the TextEdit bundle used the common JSON format when that becomes reality - I plan on making Cucumber write this file as part of running features.

Personally I want this on the web, possibly targeting non-programmers (if it gets usable enough)

Aslak

Dmitriy Korobskiy

unread,
Apr 21, 2011, 3:13:04 PM4/21/11
to cu...@googlegroups.com
I'm interested in code completion for Gherkin.

Does *any* of existing tools do it? The TextMate Bundle? The Netbeans plugin?

It could be a good enough incentive for me to use a different tool for Gherkin editing, but perhaps not good enough to pay $$ (as in for TextMate).

Given that I use a free "Eclipse" IDE
    And it works on "Macs"
    And it does code completion and much more for "Ruby"
    And it does code completion and much more for "Java"
    And it does code completion and much more for "ColdFusion"
    And I use a free and decent text editor: "TextWrangler" just for when I need to edit small files in one keystroke
When I need to find incentive to pay $$ for a different editor
Then I should win a lottery

I'm just saying :)
--
DK 
AIM: DKroot1, Skype: DKroot

Adrian Longley

unread,
Apr 21, 2011, 5:12:50 PM4/21/11
to cu...@googlegroups.com
JetBrains' RubyMine has the best implementation of this that I've seen

aslak hellesoy

unread,
Apr 21, 2011, 6:02:25 PM4/21/11
to cu...@googlegroups.com
On Thu, Apr 21, 2011 at 10:12 PM, Adrian Longley <adrian...@gmail.com> wrote:
JetBrains' RubyMine has the best implementation of this that I've seen


Yes, RubyMine has awesome Cucumber support. SpecFlow's VS plugin is fantastic too.

aslak hellesoy

unread,
Apr 21, 2011, 6:13:24 PM4/21/11
to cu...@googlegroups.com
On Thu, Apr 21, 2011 at 3:39 PM, aslak hellesoy <aslak.h...@gmail.com> wrote:


On Thu, Apr 21, 2011 at 3:12 AM, Konstantin Kudryashov <ever...@gmail.com> wrote:
I'm in! How can i help?


By improving one of the editors you use (or would like to use) I guess. How about helping me implement a Gherkin editor based on Ace? (http://ace.ajax.org/)

Here is my vision:
* A small node.js app based on express and dust for templates (I have started on that)

It was a little tricky to serve ace from a node app, so I sent this pull request: https://github.com/ajaxorg/ace/pull/217
 
* Bundle with a i18n syntax highlighter for Gherkin (I have started on that too)

aslak hellesoy

unread,
Apr 21, 2011, 8:03:45 PM4/21/11
to cu...@googlegroups.com
On Thu, Apr 21, 2011 at 11:13 PM, aslak hellesoy <aslak.h...@gmail.com> wrote:


On Thu, Apr 21, 2011 at 3:39 PM, aslak hellesoy <aslak.h...@gmail.com> wrote:


On Thu, Apr 21, 2011 at 3:12 AM, Konstantin Kudryashov <ever...@gmail.com> wrote:
I'm in! How can i help?


By improving one of the editors you use (or would like to use) I guess. How about helping me implement a Gherkin editor based on Ace? (http://ace.ajax.org/)

Here is my vision:
* A small node.js app based on express and dust for templates (I have started on that)

It was a little tricky to serve ace from a node app, so I sent this pull request: https://github.com/ajaxorg/ace/pull/217
 
* Bundle with a i18n syntax highlighter for Gherkin (I have started on that too)

That's started too:

Ok - I have tied all the loose ends together and started a project:


Have a look at it. Play with it. Impress me with your contributions and ideas :-)

Now I'm off the grid for a week or two.

Aslak

iNecas

unread,
May 1, 2011, 6:27:33 AM5/1/11
to Cukes
Hello,

I've made some commits to the gherkin-editor. In short, it's now able
to find out,
what the user have entered, search for steps that match this text,
show the suggestion using jquery-ui-autocomplete plugin, mask input
keys,
when the suggestion is on, to allow to use arrow keys, enter and
escape to
control the suggestions, and after choosing one, it replaces the
current text.

I have also made some really simple spec file using jasmine framework
for the
autocompletion.

I have made a pull request with this changes. I would like to hear
your opinion
on this approach.

Now, I am going to implement suggestions about code completion
described in
https://github.com/aslakhellesoy/gherkin/wiki/Code-Completion. I like
the idea of nesting steps
from gherkin files under their step definitions.

I would like also to do the autocompletion the way, RubyMine (and
perhaps some others)
does:
when a suggestion is chosen, in the completed text you can jump
between arguments using a tab button,
so for example the step definition
/^I fill in "[^"]+" with "[^"]+"$/
would be completed as
I fill in <arg1> with <arg2>
with <arg1> selected to be replaced immediately the user starts
typing, and when pressing <tab>,
<arg2> would be selected to be replaced.

All the best,
Ivan
On Apr 22, 2:03 am, aslak hellesoy <aslak.helle...@gmail.com> wrote:
> On Thu, Apr 21, 2011 at 11:13 PM, aslak hellesoy
> <aslak.helle...@gmail.com>wrote:
>
>
>
>
>
>
>
>
>
>
>
> > On Thu, Apr 21, 2011 at 3:39 PM, aslak hellesoy <aslak.helle...@gmail.com>wrote:
>
> >> On Thu, Apr 21, 2011 at 3:12 AM, Konstantin Kudryashov <
> >> ever....@gmail.com> wrote:
>
> >>>  I'm in! How can i help?
>
> >> By improving one of the editors you use (or would like to use) I guess.
> >> How about helping me implement a Gherkin editor based on Ace? (
> >>http://ace.ajax.org/)
>
> >> Here is my vision:
> >> * A small node.js app based on express and dust for templates (I have
> >> started on that)
>
> > It was a little tricky to serve ace from a node app, so I sent this pull
> > request:https://github.com/ajaxorg/ace/pull/217
>
> >> * Bundle with a i18n syntax highlighter for Gherkin (I have started on
> >> that too)
>
> > That's started too:
>
> >https://github.com/cucumber/ace/blob/gherkin-mode/lib/ace/mode/gherki...
> >https://github.com/cucumber/ace/blob/gherkin-mode/lib/ace/mode/gherki...

iNecas

unread,
May 1, 2011, 7:30:25 AM5/1/11
to Cukes
In addition, the support for nested examples from gherkin files is
also included in the pull request now.

On May 1, 12:27 pm, iNecas <neca...@gmail.com> wrote:
> Hello,
>
> I've made some commits to the gherkin-editor. In short, it's now able
> to find out,
>  what the user have entered, search for steps that match this text,
> show the suggestion using jquery-ui-autocomplete plugin, mask input
> keys,
> when the suggestion is on, to allow to use arrow keys, enter and
> escape to
> control the suggestions, and after choosing one, it replaces the
> current text.
>
> I have also made some really simple spec file using jasmine framework
> for the
> autocompletion.
>
> I have made a pull request with this changes. I would like to hear
> your opinion
> on this approach.
>
> Now, I am going to implement suggestions about code completion
> described  inhttps://github.com/aslakhellesoy/gherkin/wiki/Code-Completion. I like

aslak hellesoy

unread,
May 1, 2011, 6:07:56 PM5/1/11
to cu...@googlegroups.com
This looks really promising Ivan. I just pulled down the code now and will play with it on the long flight I'm about to board.

Cheers,
Aslak

aslak hellesoy

unread,
May 2, 2011, 8:28:31 PM5/2/11
to cu...@googlegroups.com
On Sun, May 1, 2011 at 5:27 AM, iNecas <nec...@gmail.com> wrote:
Hello,

I've made some commits to the gherkin-editor. In short, it's now able
to find out,
 what the user have entered, search for steps that match this text,
show the suggestion using jquery-ui-autocomplete plugin, mask input
keys,
when the suggestion is on, to allow to use arrow keys, enter and
escape to
control the suggestions, and after choosing one, it replaces the
current text.
 
I have also made some really simple spec file using jasmine framework
for the
autocompletion.

I have made a pull request with this changes. I would like to hear
your opinion
on this approach.


I've had a more thorough look at your code Ivan and must say I'm pretty impressed. I have added a few TODO items to the bottom of the README.
 
Now, I am going to implement suggestions about code completion
described  in
https://github.com/aslakhellesoy/gherkin/wiki/Code-Completion. I like
the idea of nesting steps
from gherkin files under their step definitions.

I would like also to do the autocompletion the way, RubyMine (and
perhaps some others)
does:
when a suggestion is chosen, in the completed text you can jump
between arguments using a tab button,
so for example the step definition
 /^I fill in "[^"]+" with "[^"]+"$/
would be completed as
I fill in <arg1> with <arg2>
with <arg1> selected to be replaced immediately the user starts
typing, and when pressing <tab>,
<arg2> would be selected to be replaced.


That would be great. I think regexp anchors might alienate a lot of non-technical users, so how about just displaying all groups as '??' or something.
I can quickly see the codebase growing a little out of hand, so I'd love to break the code up into smaller modules/files using http://requirejs.org/ (which is what Ace uses).

I'd like to get away from the current way where we load all scripts in HTML - I'd much prefer if the various scripts were loaded in js. This will make testing easier too I think. I'm not too familiar with requirejs - do you think you could help in that regard? 

Aslak
Reply all
Reply to author
Forward
0 new messages