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

support step auto complete with file name #311

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gclient/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@
"type": "string",
"required": false,
"default": false
},
"cucumberautocomplete.stepsBaseFile": {
"descrioption": "Provide step defintion name together with the step file name as prefix",
"type": "boolean",
"required": false,
"default": false
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions gserver/src/steps.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,10 @@ export default class StepsHandler {
res = res.replace(/\"\[\^\"\]\+\"/g, '""');
}

if (this.settings.cucumberautocomplete.stepsBaseFile) {
//remove the file prefix when the step is selected to the feature file
res = res.substr(res.indexOf("-")+1, res.length);
}
return res;
}

Expand All @@ -368,6 +372,19 @@ export default class StepsHandler {
stepRawComment;
}

getStepsBaseFile(fullStepLine: string, stepPart: string, def: Location, gherkin: GherkinType, comments: JSDocComments): Step[] {
//here requerie the step file name use "test-steps.js" pattern
let fileName = def.uri.substring(def.uri.lastIndexOf("/")+1, def.uri.lastIndexOf("-")).concat("-");
if(stepPart.startsWith("^")){
stepPart = "^".concat(fileName).concat(stepPart.substr(1,stepPart.length));
} else {
stepPart = fileName.concat(stepPart);
}

let steps = this.getSteps(fullStepLine, stepPart, def, gherkin, comments);
return steps;
}

getSteps(fullStepLine: string, stepPart: string, def: Location, gherkin: GherkinType, comments: JSDocComments): Step[] {
const stepsVariants = this.settings.cucumberautocomplete.stepsInvariants ?
this.getStepTextInvariants(stepPart) : [stepPart];
Expand Down Expand Up @@ -450,6 +467,9 @@ export default class StepsHandler {
const pos = Position.create(lineIndex, beforeGherkin.length);
const def = Location.create(getOSPath(filePath), Range.create(pos, pos));
steps = steps.concat(this.getSteps(finalLine, stepPart, def, gherkin, fileComments));
if(this.settings.cucumberautocomplete.stepsBaseFile){
steps = steps.concat(this.getStepsBaseFile(finalLine, stepPart, def, gherkin, fileComments));
}
}
return steps;
}, []);
Expand Down
3 changes: 2 additions & 1 deletion gserver/src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface Settings {
formatConfOverride?: FormatConf[],
onTypeFormat?: boolean,
gherkinDefinitionPart?: string,
stepRegExSymbol?: string
stepRegExSymbol?: string,
stepsBaseFile?: boolean
}
}