From 47a9e162d6172664c85d7e988efac0c38476c893 Mon Sep 17 00:00:00 2001 From: "Liu,Linda" Date: Tue, 10 Dec 2019 16:10:35 +0800 Subject: [PATCH] support step auto complete with file name --- gclient/package.json | 6 ++++++ gserver/src/steps.handler.ts | 20 ++++++++++++++++++++ gserver/src/typings.d.ts | 3 ++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/gclient/package.json b/gclient/package.json index fa4bcd8..c737ef9 100644 --- a/gclient/package.json +++ b/gclient/package.json @@ -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 } } } diff --git a/gserver/src/steps.handler.ts b/gserver/src/steps.handler.ts index 0daf978..b9e8e5c 100644 --- a/gserver/src/steps.handler.ts +++ b/gserver/src/steps.handler.ts @@ -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; } @@ -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]; @@ -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; }, []); diff --git a/gserver/src/typings.d.ts b/gserver/src/typings.d.ts index e85a4a9..1a97b59 100644 --- a/gserver/src/typings.d.ts +++ b/gserver/src/typings.d.ts @@ -27,6 +27,7 @@ interface Settings { formatConfOverride?: FormatConf[], onTypeFormat?: boolean, gherkinDefinitionPart?: string, - stepRegExSymbol?: string + stepRegExSymbol?: string, + stepsBaseFile?: boolean } } \ No newline at end of file