Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined step using simple Go example #244

Open
smelzer opened this issue Jul 24, 2024 · 3 comments
Open

Undefined step using simple Go example #244

smelzer opened this issue Jul 24, 2024 · 3 comments
Assignees
Labels
🍼 incomplete Blocked until more information is provided

Comments

@smelzer
Copy link

smelzer commented Jul 24, 2024

👓 What did you see?

I used the simple Godogs example code in VSCode and it runs fine. The extension is working as I see the feature file with the cucumber icon and syntax is correctly colored. However, my step definitions are underlined (error) and reporting "Undefined step". I do not have this problem with Java.

The extension says it supports Go, but I am wondering if the extension cannot actually find the step definitions. I tried to put the step definitions in the same "features" folder as the feature as well as in the root folder.

Here is the feature file:

Feature: eat godogs
  Scenario: Eat 5 out of 12
    Given there are 12 godogs
    When I eat 5
    Then there should be 7 remaining

Here is the step definition:

func TestFeatures(t *testing.T) {
  suite := godog.TestSuite{
    ScenarioInitializer: InitializeScenario,
    Options: &godog.Options{
      Format:   "pretty",
      Paths:    []string{"features"},
      TestingT: t, // Testing instance that will run subtests.
    },
  }

  if suite.Run() != 0 {
    t.Fatal("non-zero status returned, failed to run feature tests")
  }
}

func InitializeScenario(sc *godog.ScenarioContext) {
  sc.Given(`^there are (\d+) godogs$`, thereAreGodogs)
  sc.When(`^I eat (\d+)$`, iEat)
  sc.Then(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
}

Any help would be appreciated!

✅ What did you expect to see?

I should be able to jump from the step to the step definition.

📦 Which tool/library version are you using?

vscode: 1.91.1
go: 1.21.0
godog: 0.14.1

🔬 How could we reproduce it?

No response

📚 Any additional context?

No response

@kieran-ryan kieran-ryan added the 🐛 bug Defect / Bug label Aug 6, 2024
@kieran-ryan
Copy link
Member

kieran-ryan commented Aug 6, 2024

@smelzer, this appears to relate to #234 I'm afraid; if you would be willing to downgrade to VSCode 1.89 and confirm? See default path settings if any configuration required

@kieran-ryan kieran-ryan added 🍼 incomplete Blocked until more information is provided and removed 🐛 bug Defect / Bug labels Aug 6, 2024
@mitioshi
Copy link

mitioshi commented Oct 9, 2024

Having the same issue. Here's what the logs for my project look like

[Info  - 14:26:05] Initializing connection from Visual Studio Code 1.89.1
[Info  - 14:26:05] Root uri    : file:///.....
[Info  - 14:26:05] Current dir : /
[Info  - 14:26:05] Registering request handler for workspace/didChangeConfiguration failed.
[Info  - 14:26:05] Client does not support client/registerCapability. This is OK.
[Info  - 14:26:05] Cucumber Language Server 1.6.0 initialized
[Info  - 14:26:05] Scheduling reindexing in 3000 ms
[Info  - 14:26:05] Reindexing file:///.....
[Info  - 14:26:05] * Found 7 feature file(s) in ["features/**/*.feature"]
[Info  - 14:26:05] * Found 115 steps in those feature files
[Info  - 14:26:14] * Found 17 glue file(s) in [...]
[Info  - 14:26:14] * Found 0 parameter types in those glue files
[Info  - 14:26:14] * Found 0 step definitions in those glue files
[Info  - 14:26:15] * Built 51 suggestions for auto complete

Tried downgrading to 1.89 and can confirm the issue still persists.
Here's the minimal reproducible example: MRE.zip for which VSCode of the following version:

Commit: d78a74bcdfad14d5d3b1b782f87255d802b57511
Date: 2024-10-02T13:08:12.626Z
Electron: 30.5.1
ElectronBuildId: 10262041
Chromium: 124.0.6367.243
Node.js: 20.16.0
V8: 12.4.254.20-electron.0
OS: Darwin x64 23.3.0

Generates the following output:

[Info  - 16:22:33] Root uri    : file:///Users/[REDACTED]/src/tests/tests
[Info  - 16:22:33] Current dir : /
[Info  - 16:22:33] Registering request handler for workspace/didChangeConfiguration failed.
[Info  - 16:22:33] Client does not support client/registerCapability. This is OK.
[Info  - 16:22:33] Cucumber Language Server 1.6.0 initialized
[Info  - 16:22:33] Scheduling reindexing in 3000 ms
[Info  - 16:22:33] Reindexing file:///Users/mshabunin/src/tests/tests
[Info  - 16:22:33] * Found 1 feature file(s) in ["features/**/*.feature"]
[Info  - 16:22:33] * Found 3 steps in those feature files
[Info  - 16:22:33] * Found 2 glue file(s) in ["internal/scenarios/**/*.go","internal/scenarios/scenarios.go"]
[Info  - 16:22:33] * Found 0 parameter types in those glue files
[Info  - 16:22:33] * Found 0 step definitions in those glue files
[Info  - 16:22:33] * Built 3 suggestions for auto complete```

@mitioshi
Copy link

Would also add to my previous comment that https://github.com/cucumber/language-service seems to resolve step definitions correctly in the main branch. That is, I ran tests for ExpressionBuilder#build with the test file substituted with foo.go I linked in the archive above and it does find the following expression in the glue file

[
  {
    expression: CucumberExpression {
      expression: 'there are 12 godogs',
      parameterTypeRegistry: [ParameterTypeRegistry],
      parameterTypes: [],
      ast: [Node],
      treeRegexp: [TreeRegexp]
    },
    locationLink: {
      targetRange: [Object],
      targetSelectionRange: [Object],
      targetUri: 'file:///Users/[REDACTED]/src/language-service/test/language/testdata/go/StepDefinitions.go'
    }
  }
]

The tests above fail in [email protected] which [email protected] uses in dependencies. Hence why I see the 'undefined-step' errors in VSCode. AFAICT, this is due to tree-sitter queries not matching methods(only functions) containing step definitions. cucumber/language-service@0d28333 seems to have fixed this, however this commit haven't yet landed in any release.

@kieran-ryan how hard would it be to propagate this fix from https://github.com/cucumber/language-service up to the cucumber vscode extension? Should I submit an issue in the language-service repo for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍼 incomplete Blocked until more information is provided
Projects
None yet
Development

No branches or pull requests

3 participants