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

Fix unmatched step detection and add snippet support for Python/Behave backend

Open Copilot opened this issue 4 months ago • 0 comments

The Python/Behave backend was not detecting unmatched steps (steps without glue code) or providing snippets for quick-fix code generation.

Changes

BehaveGlueJob.java

  • Parse UNDEFINED STEPS and snippet sections from behave output
  • Map extracted snippets to unmatched steps by step text
  • Switch from BehaveMarkerFactory.unmatchedSteps() to MarkerFactory.missingSteps() with snippet support

Parsing logic

// State machine tracks three sections:
// 1. Matched steps (@given... # file.py:line)
// 2. UNDEFINED STEPS[n]: list of unmatched steps
// 3. Snippet section with Python code to implement

Map<String, String> snippetsMap = new HashMap<>();  // step text -> snippet code
Map<Integer, Collection<String>> unmatchedStepsWithSnippets = new HashMap<>();

// Match snippets to steps by text, create markers with snippet attributes
MarkerFactory.missingSteps(resource, unmatchedStepsWithSnippets, pluginId, false);

Behave output structure:

UNDEFINED STEPS[3]:
  When I add 2 and 3 numbers              # calculator.feature:8

You can implement step definitions for undefined steps with these snippets:

@when(u'I add 2 and 3 numbers')
def step_impl(context):
    raise StepNotImplementedError(u'When I add 2 and 3 numbers')

The snippet attribute enables Eclipse's quick-fix framework to offer code generation for missing step implementations.

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)
  • http://download.eclipse.org:80/releases/2025-09/content.jar
    • Triggering command: REDACTED, pid is -1 (http block)
  • http://download.eclipse.org:80/releases/2025-09/p2.index
    • Triggering command: REDACTED, pid is -1 (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix unmatched steps and implement snippet support</issue_title> <issue_description>Currently it seems unmatched steps are not showing an error marker when using behave/python backend. Apart from that we want snippet support but this only works if unmatched steps are correctly detected and shown as a marker.

If there are unmatched steps the output looks like this

You can implement step definitions for undefined steps with these snippets:

@when(u'I add 2 and 3 numbers')
def step_impl(context):
    raise NotImplementedError(u'STEP: When I add 2 and 3 numbers')


@given(u'I have a calculatorx')
def step_impl(context):
    raise NotImplementedError(u'STEP: Given I have a calculatorx')


@given(u'I have a calculatorrrr')
def step_impl(context):
    raise NotImplementedError(u'STEP: Given I have a calculatorrrr')

@given('I have a calculator')             # python-calculator/features/steps/calculator_steps.py:19
  Given I have a calculator               # python-calculator/features/calculator.feature:7

@when('I subtract {a:d} from {b:d}')      # python-calculator/features/steps/calculator_steps.py:27
  When I subtract 3 from 5                # python-calculator/features/calculator.feature:13

@when('I multiply {a:d} by {b:d}')        # python-calculator/features/steps/calculator_steps.py:31
  When I multiply 2 by 3                  # python-calculator/features/calculator.feature:18

@then('the result should be {expected:d}')  # python-calculator/features/steps/calculator_steps.py:35
  Then the result should be 5               # python-calculator/features/calculator.feature:9
  Then the result should be 2               # python-calculator/features/calculator.feature:14
  Then the result should be 6               # python-calculator/features/calculator.feature:19

UNUSED STEP DEFINITIONS[1]:
  @when('I add {a:d} and {b:d}')          # python-calculator/features/steps/calculator_steps.py:23

UNDEFINED STEPS[3]:
  When I add 2 and 3 numbers              # python-calculator/features/calculator.feature:8
  Given I have a calculatorx              # python-calculator/features/calculator.feature:12
  Given I have a calculatorrrr            # python-calculator/features/calculator.feature:17

From the output we see UNDEFINED STEPS gives us a lit of where we need to do something, and we can match the text against the proposed snippets.

We then can use this to build a map we later pass to the markerfactory to get a quickfix. </issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes cucumber/cucumber-eclipse#572

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Oct 26 '25 13:10 Copilot