Skip to content

Add textDocument/references for step definitions - #146

Open
seflue wants to merge 2 commits into
cucumber:mainfrom
seflue:step-references
Open

seflue wants to merge 2 commits into
cucumber:mainfrom
seflue:step-references

Conversation

@seflue

@seflue seflue commented Sep 12, 2026

Copy link
Copy Markdown

Closes #145

onReferences returns the location of every Gherkin step matched by the step definitions whose targetRange contains the request position.

An outline step's own text still contains the <placeholders> and matches no expression. We therefore match it through the compiled pickles, because they carry the text with each Examples row substituted. The pickles yield one match per row, but the step exists only once in the file, so it is reported as a single location, at the outline step's line.

References need the Gherkin sources after indexing, so reindex() now keeps them on the instance instead of dropping them once the step texts for completion are extracted. @cucumber/gherkin and @cucumber/messages become direct dependencies (both were already resolved transitively through language-service).

Body positions resolve only as far as targetRange is accurate. With language-service 1.7.0 it is for every language except Rust, where the range spans the whole file (cucumber/language-service#315), so a request from anywhere in a Rust glue file would match every step definition in it. The second commit therefore falls back to targetSelectionRange when targetRange starts at the top of the file. Until #315 is released, Rust users need the cursor on the expression literal.

The VSCode extension already attaches to glue files, so references work there without a change.

Go-to-definition only works from a Gherkin step to its step
definition. Editors that ask the reverse question ("which steps use
this definition?") got nothing, because the server neither advertised
referencesProvider nor kept the Gherkin sources after indexing.

Match every Gherkin step against the expressions located at the
request position. Steps are taken from the compiled pickles, so a
Scenario Outline step matches with its Examples values substituted
and is reported once, at the outline's line.
With language-service 1.7.0 every Rust step definition reports the
whole glue file as its target range, so a references request from
anywhere in that file resolves to every step definition in it, even
from a function that is not a step definition. Test such links
against the expression literal instead: the cursor has to be on the
literal, body positions return nothing. Once
cucumber/language-service#315 is released the ranges are real and
the fallback no longer triggers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Find references from a step definition to the Gherkin steps using it

1 participant