vim-cucumber icon indicating copy to clipboard operation
vim-cucumber copied to clipboard

Adds js as ft, supporting cucumberjs.

Open jbnicolai opened this issue 10 years ago • 7 comments

Review on Reviewable

jbnicolai avatar Aug 25 '15 11:08 jbnicolai

@jbnicolai does this work? @tpope could this be added?

christopher-francisco avatar Apr 15 '20 15:04 christopher-francisco

I tried something similar with my config with no luck. As I see it javascript syntax need a different regex expression to process step definitions. Would love to see javascript supported myself

ArtemSmaznov avatar Feb 19 '21 23:02 ArtemSmaznov

I think that was my concern that I never got around to asking about. Can anyone else speak to this? Ruby and JS regexps are both Perl based so I wouldn't think it would be an automatic deal breaker.

tpope avatar Feb 23 '21 01:02 tpope

I have played around a bit with this and I think the current regex expression doest pick up JS definitions as they end in a comma instead of a ) like in ruby:

Given('i define the step definition', () => {
  // Some code
});

It wouldn't be too hard to add a second regex expression specifically for JS filetypes.

I have managed to get it to work on my side with a very dirty one but it doesn't work with step definitions that pass arguments like:

Given('i define the {string} step definition', (arg) => {
 // Some code
});

I wonder does that work with ruby or it a limitation of the plugin? I only used JS myself.

ArtemSmaznov avatar Feb 23 '21 01:02 ArtemSmaznov

The \%(|[^|]*|\s*\)\= part of the regexp is designed to match the Ruby equivalent of |arg1, arg2|. You'll need to do similar for JavaScript.

Here's a starting point for anyone brave enough to attempt:

let step_pattern = '\C^\s*\K\k*\>\s*(\=\s*\zs\S.\{-\}\ze\s*\%()\=\s*\%(do\|{\)\s*\%(|[^|]*|\s*\)\=\%($\|#\)\|YOUR JS VERSION HERE\%($\|//\)\)'

tpope avatar Feb 23 '21 01:02 tpope

@tpope I would like to give this a go but I am completely greed when it comes to regex. Any chance you can recommend a website where I can try composing it with more immediate feedback? Tried https://regexr.com/ but it does seem to be liking the available expression - I am guessing it uses a different engine or something.

ArtemSmaznov avatar Mar 16 '21 14:03 ArtemSmaznov

Vim has a pattern engine of its own design. I don't know of any websites, but a good starting point might be :help perl-patterns to tell you the differences between that and a more popular option.

tpope avatar Mar 17 '21 07:03 tpope