alexkrechik / VSCucumberAutoComplete

Cucumber (Gherkin) Full Support Extension for VSCode
https://marketplace.visualstudio.com/items?itemName=alexkrechik.cucumberautocomplete
MIT License
331 stars 82 forks source link

Unable to get autocomplete working #323

Closed VJose6 closed 4 years ago

VJose6 commented 4 years ago

Describe the bug I am unable to get autocomplete working with simple example in https://github.com/cucumber/cucumber-js/blob/master/docs/nodejs_example.md

To Reproduce Steps to reproduce the behavior:

  1. In a workspace, add existing blank folder "vscode-cukes-test". Create package.json.
  2. Follow the steps in https://github.com/cucumber/cucumber-js/blob/master/docs/nodejs_example.md to complete the simple cucumber example.
    
    PS C:\codeSLS\vscode-cukes-test> ./node_modules/.bin/cucumber-js             
    ............

4 scenarios (4 passed) 12 steps (12 passed) 0m00.001s


3. Create .vscode/setting.json
4. Restart vscode
5. Formatting (Shft+Alt+F) in feature file works but autocomplete  (Ctrl+Space) does not

**Expected behavior**
Autocomplete should work

**Screenshots**
Project Tree
![image](https://user-images.githubusercontent.com/55995352/76088910-d6124780-5f86-11ea-886d-ee78915d1a73.png)
VSCode Settings
![image](https://user-images.githubusercontent.com/55995352/76089013-f8a46080-5f86-11ea-81d3-6b6541e67d78.png)
Current Autocomplete Recommended
![image](https://user-images.githubusercontent.com/55995352/76089421-a0219300-5f87-11ea-8c25-481155cdcc9f.png)

**Cucumberautocomplete part of VSCode settings:**

{ "cucumberautocomplete.steps": [ "features/support/.js" ], "cucumberautocomplete.syncfeatures": "features/feature", "cucumberautocomplete.strictGherkinCompletion": true, "cucumberautocomplete.strictGherkinValidation": true, "cucumberautocomplete.smartSnippets": true, "cucumberautocomplete.stepsInvariants": true, "cucumberautocomplete.pages": { "users": "test/features/page_objects/users.storage.js", "pathes": "test/features/page_objects/pathes.storage.js", "main": "test/features/support/page_objects/main.page.js" }, "cucumberautocomplete.skipDocStringsFormat": true, "cucumberautocomplete.formatConfOverride": { "And": 3, "But": "relative", }, "cucumberautocomplete.onTypeFormat": true, "editor.quickSuggestions": { "comments": false, "strings": true, "other": true }, "cucumberautocomplete.gherkinDefinitionPart": "(Given|When|Then)\(", "cucumberautocomplete.stepRegExSymbol": "'" }


**Step definition:**
If applicable, add example of step definition:

// features/support/steps.js const { Given, When, Then } = require("cucumber"); const { expect } = require("chai");

Given("a variable set to {int}", function(number) { this.setTo(number); });

When("I increment the variable by {int}", function(number) { this.incrementBy(number); });

Then("the variable should contain {int}", function(number) { expect(this.variable).to.eql(number); });

// features/support/world.js const { setWorldConstructor } = require("cucumber");

class CustomWorld { constructor() { this.variable = 0; }

setTo(number) { this.variable = number; }

incrementBy(number) { this.variable += number; } }

setWorldConstructor(CustomWorld);


**Gherkin step line**
If applicable, add step line from gherkin file

features/simple_math.feature

Feature: Simple maths In order to do maths As a developer I want to increment variables

Scenario: easy maths
    Given a variable set to 1
    When I increment the variable by 1
    Then the variable should contain 2

Scenario Outline: much more complex stuff
    Given a variable set to <var>
    When I increment the variable by <increment>
    Then the variable should contain <result>

    Examples:
        | var | increment | result |
        | 100 | 5         | 105    |
        | 99  | 1234      | 1333   |
        | 12  | 5         | 17     |
combmag commented 4 years ago

any update on this please?

Cubo25 commented 4 years ago

I have same issue ! Cant make cucumber autocomplete work ! "Was unable to find steps for ..."

alexkrechik commented 4 years ago

@c-magri @Cubo25 could you please provide step definition, gherkin line examples, and config file? I'm unable to reproduce the original issue, so this info would help.

combmag commented 4 years ago

@alexkrechik this happens to me only when i use vscode workspace

i have a file myapp.workspace which has the following

{
"folders": [
        {
            "name": "E2E App",
            "path": "apps/e2e"
        },
                {
            "name": "Root App",
            "path": "apps/e2e"
        }],
"settings": {
        "cucumberautocomplete.steps": [
            "apps/e2e/src/step_definitions/*.ts"
        ],
        "cucumberautocomplete.syncfeatures": "apps/e2e/src/features/*.feature",
        "cucumberautocomplete.strictGherkinCompletion": true,
}
}

I'll also try to create a sample repo for this

combmag commented 4 years ago

After debugging your extenstion I managed to figure out what was the issue, basically the "Root App" inside the workspace need to be the first one in the folders or else the paths will be wrong

This works:

{
"folders": [
{
            "name": "Root App",
            "path": "."
        },
        {
            "name": "E2E App",
            "path": "apps/e2e"
        },

],

This doesn't work:

{
"folders": [
    {
            "name": "E2E App",
            "path": "apps/e2e"
        },
{
            "name": "Root App",
            "path": "."
        },

],

@alexkrechik what might make sense is that part of the cucumberautocomplete an optional rootDir would be added so it would make it easier. Any thoughts?

VJose6 commented 4 years ago

The settings section in my workspace file was empty. When i add the cucumber extension settings there, my steps get underlined with yellow. image So, unlike before, now it recognizes that step definitions are defined but is pointing to the wrong directory. Knowing how absolute location, of step definitions, is resolved in the above workspace configuration would help here. Also, not sure why the project settings was not identified in the workspace configuration. Ideally, project settings should supersede workspace setting. Not sure if it is due to the extension or the design of VSCode IDE.

alexkrechik commented 4 years ago

After debugging your extenstion I managed to figure out what was the issue, basically the "Root App" inside the workspace need to be the first one in the folders or else the paths will be wrong

This works:

{
"folders": [
{
          "name": "Root App",
          "path": "."
      },
      {
          "name": "E2E App",
          "path": "apps/e2e"
      },

],

This doesn't work:

{
"folders": [
  {
          "name": "E2E App",
          "path": "apps/e2e"
      },
{
          "name": "Root App",
          "path": "."
      },

],

@alexkrechik what might make sense is that part of the cucumberautocomplete an optional rootDir would be added so it would make it easier. Any thoughts?

If the issue still valid, could you please open it as a separate ticket?

alexkrechik commented 4 years ago

The settings section in my workspace file was empty. When i add the cucumber extension settings there, my steps get underlined with yellow. image So, unlike before, now it recognizes that step definitions are defined but is pointing to the wrong directory. Knowing how absolute location, of step definitions, is resolved in the above workspace configuration would help here. Also, not sure why the project settings was not identified in the workspace configuration. Ideally, project settings should supersede workspace setting. Not sure if it is due to the extension or the design of VSCode IDE.

All the paths should be related to the project root. Please reopen this issue or comment here, if there are some problems with them.

jfstephe commented 3 years ago

Hopefully this may help someone but we found (by adding some debug info into the extension) that the 'root' of the docker container based workspace project in the extension was /workspaces/projectName/.vscode/

As such we had to 'go up' one level in the steps globs:

"cucumberautocomplete.steps": [
      "../client/src/*.steps.ts",
      "../client/src/**/*.steps.ts",
      "../server/src/*.steps.ts",
      "../server/src/**/*.steps.ts"
    ],

@alexkrechik - minor suggestion of, if no steps/feature files are found perhaps you could log the full resolved paths being used? PS Awesome plugin.

godrose commented 2 years ago

@alexkrechik Hey there. Is there any dump location for the logs? Thanks

alexkrechik commented 2 years ago

@alexkrechik Hey there. Is there any dump location for the logs? Thanks

Looks like that no. Usually I'm using separate procedure (server attaching) to see whats happens under the hood.

MNorgren commented 2 years ago

@combmag

This was the fix for me. I had to switch the folder in my workspace to get it working. It is hacky, but it worked. Thank you!

Develop5 commented 1 year ago

This link does not work any longer: https://github.com/cucumber/cucumber-js/blob/master/docs/nodejs_example.md