cucumber / language-server

Cucumber Language Server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Glue code not being found

richwyantoddball opened this issue ¡ comments

👓 What did you see?

I'm starting to write some features with a proof-of-concept repo for automated testing. The tech stack(so far) is Java, Maven, and Sikuli and I believe I have the right coordinates in my pom to throw Cucumber into the mix. I added version 1.2.3 in VS Code and started to make some step defs. I noticed they weren't being recognized nor could I make a new one from a feature file. The logs indicate Cucumber Language server can't find anything. I've tried the default setting for cucumber.features and cucumber.glue, hard-coding the direct paths, and escaping the /s. Nothing's taken root. Relevant settings in settings.json are currently:

    "cucumber.features": [
        "src/test/**/*.feature",
        "src/test/resources/feature/*.feature"
    ],

    "cucumber.glue": [
        "src/test/**/*.java",
        "src/test/java/com/oddball/xmlcomparemaven/*.java"
    ]

Here is the log from 'Cucumber Language Server`:

[Info  - 8:38:40 AM] Reindexing...
[Info  - 8:38:40 AM] * Found 0 feature file(s) in ["src/test/**/*.feature","src/test/resources/feature/*.feature"]
[Info  - 8:38:40 AM] * Found 0 steps in those feature files
[Info  - 8:38:40 AM] * Found 0 glue file(s) in ["src/test/**/*.java","src/test/java/com/oddball/xmlcomparemaven/*.java"]
[Info  - 8:38:40 AM] * Found 0 parameter types in those glue files
[Info  - 8:38:40 AM] * Found 0 step definitions in those glue files
[Info  - 8:38:40 AM] Generating diagnostics
[Info  - 8:38:40 AM] * Built 0 suggestions for auto complete
[Info  - 8:38:40 AM] Unable to generate step definition. Please create one first manually.

This is reflected when I execute the runner class:
image

✅ What did you expect to see?

  • The stepdef being recognized
  • The ability to add a new stepdef from the feature file
  • Ability to run Scenarios from the Runner class

📦 Which tool/library version are you using?

  • Mac OSX 12.4 (M1)
  • VS Code 1.67.2
  • Cucumber for Visual Studio Code 1.2.3
  • The last time I mentioned this I posted the pom I was told it was irrelevant. If that changes I can post it on request.

🔬 How could we reproduce it?

  • Install VS Code and relevant plugins
  • Add Runner and Stepdef classes
  • Configure settings.json with above configuration
  • Configure pom.xml with relevant Maven coordinates
  • Save everything, restart VS Code
  • pom.xml > Update project
  • Change the Output tab to Cucumber Language Server
  • Attempt to use existing stepdefs, write new ones from the feature file, and run scenarios from the Runner class.

📚 Any additional context?

I've used Cucumber before in IntelliJ and Eclipse. This is my first time using this in VS Code. This could very well be something I am doing wrong instead of a bug. For original context, see cucumber/language-service#45

Thanks for the detailed report @richwyantoddball.

Please install extension 1.2.4 which has a bit more logging. At the top of the log you should see something like this:

[Info  - 15:34:53] Initializing connection from Visual Studio Code 1.67.2
[Info  - 15:34:53] Root path: /some/absolute/path/to/your/project

The globs you specify for features and glue are relative to the Root path.

The only reason I can think of that 0 files are found is that you don't have any files matching your globs. Hopefully the logged Root path will help you verify that you actually have .feature files under {Root path}/${features globs} and similarly for glue (.java) files.

Thanks, @aslakhellesoy. You're right, it's a path issue. I upgraded to 1.2.4 that and this was the log, including root path:

[Info  - 10:07:45 AM] Initializing connection from Visual Studio Code 1.67.2
[Info  - 10:07:45 AM] Root path: /Users/richardwyant/xmlcomparemaven
[Info  - 10:07:45 AM] Registering request handler for workspace/didChangeConfiguration failed.
[Info  - 10:07:45 AM] Client does not support client/registerCapability. This is OK.
[Info  - 10:07:45 AM] Cucumber Language Server 0.12.7 initialized
[Info  - 10:07:45 AM] Scheduling reindexing in 3000 ms
[Info  - 10:07:45 AM] Scheduling reindexing in 3000 ms
[Info  - 10:07:45 AM] Generating diagnostics
[Info  - 10:07:45 AM] Reindexing...
[Info  - 10:07:45 AM] * Found 0 feature file(s) in ["src/test/**/*.feature","src/test/resources/feature/*.feature"]
[Info  - 10:07:45 AM] * Found 0 steps in those feature files
[Info  - 10:07:45 AM] * Found 0 glue file(s) in ["src/test/**/*.java","src/test/java/com/oddball/xmlcomparemaven/*.java"]
[Info  - 10:07:45 AM] * Found 0 parameter types in those glue files
[Info  - 10:07:45 AM] * Found 0 step definitions in those glue files
[Info  - 10:07:45 AM] Generating diagnostics
[Info  - 10:07:45 AM] * Built 0 suggestions for auto complete
[Info  - 10:07:45 AM] Unable to generate step definition. Please create one first manually.

I hard-coded the root path above and now it's finding things.

    "cucumber.features": [
        "src/test/**/*.feature",
        "src/test/resources/feature/*.feature",
        "/Users/richardwyant/xmlcomparemaven/xmlcompare/src/test/resources/feature/*.feature"
    ],

    "cucumber.glue": [
        "src/test/**/*.java",
        "src/test/java/com/oddball/xmlcomparemaven/*.java",
        "/Users/richardwyant/xmlcomparemaven/xmlcompare/src/test/java/com/oddball/xmlcomparemaven/*.java"
    ]
[Info  - 10:14:42 AM] Reindexing...
[Info  - 10:14:42 AM] * Found 1 feature file(s) in ["src/test/**/*.feature","src/test/resources/feature/*.feature","/Users/richardwyant/xmlcomparemaven/xmlcompare/src/test/resources/feature/*.feature"]
[Info  - 10:14:42 AM] * Found 2 steps in those feature files
[Info  - 10:14:42 AM] * Found 4 glue file(s) in ["src/test/**/*.java","src/test/java/com/oddball/xmlcomparemaven/*.java","/Users/richardwyant/xmlcomparemaven/xmlcompare/src/test/java/com/oddball/xmlcomparemaven/*.java"]
[Info  - 10:14:42 AM] * Found 0 parameter types in those glue files
[Info  - 10:14:42 AM] * Found 1 step definitions in those glue files
[Info  - 10:14:42 AM] Generating diagnostics
[Info  - 10:14:42 AM] * Built 2 suggestions for auto complete

How would I adjust settings.json to include the root path so it's not hard-coded in?

Also it's still not allowing me to create a new stepdef from the feature, but this is minor so far.
image

How would I adjust settings.json to include the root path so it's not hard-coded in?

You shouldn't have to include the root path in your glob. This should be fine, because the working directory for the language server is the Root path.

"cucumber.features": [
  "src/test/**/*.feature"
],

But that's the same as in the default setting, so you should be able to delete it completely. Same for glue. You can set it to either this:

"cucumber.glue": [
  "src/test/**/*.java"
],

Or delete it and rely on the defaults. In short, don't override any settings.

Also it's still not allowing me to create a new stepdef from the feature, but this is minor so far.

In VSCode, you do this with a quick-fix. Press ⌘. to bring up the quick-fix popup where you can choose a file to write your step definition to.

Hmm... I tried the glob with just those and got the "can't find anything" issue again.

[Info  - 11:06:25 AM] Reindexing...
[Info  - 11:06:25 AM] * Found 0 feature file(s) in ["src/test/**/*.feature"]
[Info  - 11:06:25 AM] * Found 0 steps in those feature files
[Info  - 11:06:25 AM] * Found 0 glue file(s) in ["src/test/**/*.java"]
[Info  - 11:06:25 AM] * Found 0 parameter types in those glue files
[Info  - 11:06:25 AM] * Found 0 step definitions in those glue files
[Info  - 11:06:25 AM] Generating diagnostics
[Info  - 11:06:25 AM] * Built 0 suggestions for auto complete
[Info  - 11:06:26 AM] Unable to generate step definition. Please create one first manually.
[Info  - 11:06:26 AM] Unable to generate step definition. Please create one first manually.

For grins, I tried putting this in the $PATH. Didn't work.

I also found the add-a-new-stepdef is working for Quick fix:
image

That's really odd. I wonder if the language server somehow runs in a different work directory than Root path. I can probably work around this by prepending Root path to the globs. I can also log what process.cwd() is, in case it's different from Root path...

But until I fix that, just use the absolute paths in globs. Did you get generate step definition to work with ⌘.?

I've released 1.2.6 which doesn't fix anything, but it now prints this:

[Info  - 18:26:45] Root path   : /some/absolute/path/to/your/project
[Info  - 18:26:45] Current dir : /some/absolute/path/to/your/project

Can you tell me if those two lines print out the same directory for you @richwyantoddball? If they are the same I'm at a loss as to why your relative globs don't find anything...

I got 1.2.6 and re-started VS Code. It looks like root and current are in agreement:

[Info  - 1:24:07 PM] Initializing connection from Visual Studio Code 1.67.2
[Info  - 1:24:07 PM] Root path   : /Users/richardwyant/xmlcomparemaven
[Info  - 1:24:07 PM] Current dir : /Users/richardwyant/xmlcomparemaven

For giggles, I put in the short version and still got nothing again.
image

I also tried variables and the folder's settings.json instead of the user's , which is where we've been adjusting things so far. Same thing.
image

image

And, yes, it does create a new stepdef:
image

Edit: This was working and appears not to anymore.

When I put back the original hardcoded path, it doesn't want to even recognize edits anymore.

image

Don’t forget that globs use ** to mean “subdirectory at any depth”. Without this it won’t descend into subdirectories.

But I guess your globs are fine since they specify the full path to the directory containing files.

So weird!!!

Would you be able to add more debug statements and try to diagnose the source of this bug yourself? It’s hard for me to find out what’s wrong without access to your environment.

The process is described in CONTRIBUTING.md

I was able to get steps recognized again by uninstalling and reinstalling the extension. Still having troubles executing a test. Will poke around and post any solutions I find.

 [Info  - 9:04:02 AM] Initializing connection from Visual Studio Code 1.67.2
[Info  - 9:04:02 AM] Root path   : /Users/richardwyant/xmlcomparemaven
[Info  - 9:04:02 AM] Current dir : /Users/richardwyant/xmlcomparemaven
[Info  - 9:04:02 AM] Registering request handler for workspace/didChangeConfiguration failed.
[Info  - 9:04:02 AM] Client does not support client/registerCapability. This is OK.
[Info  - 9:04:02 AM] Cucumber Language Server 0.12.9 initialized
[Info  - 9:04:02 AM] Scheduling reindexing in 3000 ms
[Info  - 9:04:02 AM] Reindexing...
[Info  - 9:04:02 AM] * Found 1 feature file(s) in ["/Users/richardwyant/xmlcomparemaven/xmlcompare/src/test/resources/feature/*.feature"]
[Info  - 9:04:02 AM] * Found 2 steps in those feature files
[Info  - 9:04:02 AM] * Found 4 glue file(s) in ["/Users/richardwyant/xmlcomparemaven/xmlcompare/src/test/java/com/oddball/xmlcomparemaven/*.java"]

The test execution was resolved by moving the feature to resources/com/oddball/xmlcomparemaven and adjusting @SelectClasspathResource:
image

I'm able to proceed with this. Thanks for working with me, @aslakhellesoy.