cucumber / language-service

Cucumber Language Service
MIT License
18 stars 27 forks source link

Cannot index Python glue files containing 'name' keyword arguments #181

Closed kieran-ryan closed 8 months ago

kieran-ryan commented 10 months ago

👓 What did you see?

The Language Service looks for the use of the 'name' keyword inside an argument list of callables for detecting Cucumber Parameter Types, using a tree-sitter query.

This becomes an issue when you use 'name' as a keyword argument for other purposes inside glue code; as an exception is triggered due to the remainder of Parameter Type keyword arguments being missing, and doesn't index the file.

import dataclasses

@dataclasses.dataclass
class Color:
    name: str

@when('I select the theme colo(u)r {}')
def step_when(context, selected_color: str):
    """Select a colour on the profile configuration page."""
    #  This call is incorrectly considered an invalid attempt to define a Parameter Type:
    selected_color = Color(name="red")
    context.selected_color = selected_color.name
Reindexing file:://environment
* Found 1 feature file(s) in ["features/**/*.feature"]
* Found 1 step in those feature files
* Found 1 glue file(s) in ["features/**/*.py"]
Failed to reindex: Cannot read properties of null (reading 'type')

Potential solutions could include not raising fatal errors for "invalid" parameter type definitions and to index the remainder of the file OR to provide more targeted and specific queries for Parameter Types to prevent false positives.

✅ What did you expect to see?

Indexing occurs on relevant glue code only (step definitions and parameter types) and not on irrelevant calls with a 'name' keyword argument.

📦 Which tool/library version are you using?

Cucumber Language Service 1.4.0

🔬 How could we reproduce it?

  1. Copy the aforementioned Python glue code example to a repository.
  2. Open the repository in Visual Studio Code
  3. Install the Cucumber extension
  4. Open the 'Output' window and select 'Cucumber Language Server'
  5. Check the logs provide a 'Failed to index' error