Skip to content

Commit 1ff799f

Browse files
committed
Use gherkinDialect supplied in document for and-keyword
1 parent da3ebbe commit 1ff799f

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

Reqnroll.VisualStudio/Editor/Services/Formatting/GherkinDocumentFormatter.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@ public void FormatGherkinDocument(DeveroomGherkinDocument gherkinDocument, Docum
1212
return;
1313

1414
SetTagsAndLine(lines, gherkinDocument.Feature, string.Empty);
15-
SetLinesForChildren(lines, gherkinDocument.Feature.Children, formatSettings, formatSettings.FeatureChildrenIndentLevel);
15+
SetLinesForChildren(lines, gherkinDocument.Feature.Children, formatSettings, formatSettings.FeatureChildrenIndentLevel, gherkinDocument.GherkinDialect);
1616
}
1717

1818
private void SetLinesForChildren(DocumentLinesEditBuffer lines, IEnumerable<IHasLocation> hasLocation,
19-
GherkinFormatSettings formatSettings, int indentLevel)
19+
GherkinFormatSettings formatSettings, int indentLevel, GherkinDialect gherkinDialect)
2020
{
21-
var dialectProvider = ReqnrollGherkinDialectProvider.Get(formatSettings.Language);
22-
2321
foreach (var featureChild in hasLocation)
2422
{
2523
SetTagsAndLine(lines, featureChild, GetIndent(formatSettings, indentLevel));
2624

2725
if (featureChild is Rule rule)
2826
SetLinesForChildren(lines, rule.Children, formatSettings,
29-
indentLevel + formatSettings.RuleChildrenIndentLevelWithinRule);
27+
indentLevel + formatSettings.RuleChildrenIndentLevelWithinRule, gherkinDialect);
3028

3129
if (featureChild is ScenarioOutline scenarioOutline)
3230
foreach (var example in scenarioOutline.Examples)
@@ -39,12 +37,12 @@ private void SetLinesForChildren(DocumentLinesEditBuffer lines, IEnumerable<IHas
3937
}
4038

4139
if (featureChild is IHasSteps hasSteps)
42-
FormatSteps(lines, formatSettings, indentLevel, hasSteps, dialectProvider);
40+
FormatSteps(lines, formatSettings, indentLevel, hasSteps, gherkinDialect);
4341
}
4442
}
4543

4644
private void FormatSteps(DocumentLinesEditBuffer lines, GherkinFormatSettings formatSettings, int indentLevel,
47-
IHasSteps hasSteps, GherkinDialectProvider dialectProvider)
45+
IHasSteps hasSteps, GherkinDialect gherkinDialect)
4846
{
4947
var previousKeyword = "";
5048

@@ -62,7 +60,7 @@ private void FormatSteps(DocumentLinesEditBuffer lines, GherkinFormatSettings fo
6260
{
6361
if (step.Keyword == previousKeyword)
6462
{
65-
var andKeyword = GetAndKeyword(dialectProvider);
63+
var andKeyword = GetAndKeyword(gherkinDialect);
6664
newKeyword = $"{andKeyword}";
6765
}
6866
else
@@ -84,9 +82,9 @@ private void FormatSteps(DocumentLinesEditBuffer lines, GherkinFormatSettings fo
8482
}
8583
}
8684

87-
private static string GetAndKeyword(GherkinDialectProvider dialectProvider)
85+
private static string GetAndKeyword(GherkinDialect gherkinDialect)
8886
{
89-
return dialectProvider.DefaultDialect.AndStepKeywords.First(keyword => keyword != GherkinDialect.AsteriskKeyword);
87+
return gherkinDialect.AndStepKeywords.First(keyword => keyword != GherkinDialect.AsteriskKeyword);
9088
}
9189

9290
private void SetTagsAndLine(DocumentLinesEditBuffer lines, IHasLocation hasLocation, string indent)

Reqnroll.VisualStudio/Editor/Services/Formatting/GherkinFormatSettings.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public class GherkinFormatSettings
2323

2424
public string TableCellPadding => new(' ', Configuration.TableCellPaddingSize);
2525

26-
public string Language { get; set; } = "en-US";
2726

2827
public static GherkinFormatSettings Load(IEditorConfigOptionsProvider editorConfigOptionsProvider,
2928
IWpfTextView textView, DeveroomConfiguration configuration)
@@ -40,8 +39,7 @@ public static GherkinFormatSettings Load(IEditorConfigOptionsProvider editorConf
4039
var formatSettings = new GherkinFormatSettings
4140
{
4241
Indent = convertTabsToSpaces ? new string(' ', indentSize) : new string('\t', 1),
43-
Configuration = gherkinFormatConfiguration,
44-
Language = configuration?.DefaultFeatureLanguage ?? "en-US"
42+
Configuration = gherkinFormatConfiguration
4543
};
4644

4745
return formatSettings;

Reqnroll.VisualStudio/ProjectSystem/Configuration/ProjectScopeDeveroomConfigurationProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ private ConfigSource GetProjectConfigFilePath(string fileName)
116116
{
117117
var projectFolder = _projectScope.ProjectFolder;
118118
var fileSystem = _projectScope.IdeScope.FileSystem;
119-
var assemblyPath = Path.GetDirectoryName(_projectScope.OutputAssemblyPath);
120119

121-
var configFilePath = fileSystem.GetFilePathIfExists(Path.Combine(assemblyPath ?? projectFolder, fileName));
120+
var configFilePath = fileSystem.GetFilePathIfExists(Path.Combine(projectFolder, fileName));
122121

123122
if (fileName.Equals(SpecFlowAppConfigFileName)) configFilePath ??= GetAppConfigPathFromProject();
124123
if (configFilePath == null)

Tests/Reqnroll.VisualStudio.Specs/Features/Editor/Commands/AutoFormatDocumentCommand.feature

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,35 @@ Scenario: Formatting of Descriptions and Comments are not changed
301301
Todo: handle negative numbers
302302
303303
Given I have entered 50 into the calculator
304+
"""
305+
306+
Rule: Auto format should replace repeated keywords with "And"
307+
308+
Scenario: Repeating keywords are replaced with "And"
309+
310+
Given there is a Reqnroll project scope
311+
And the following feature file in the editor
312+
"""
313+
Feature: Addition
314+
315+
Scenario: Add two numbers
316+
Given I have entered 50 into the calculator
317+
Given I have entered 70 into the calculator
318+
When I add them
319+
When I check the result
320+
Then there should be no error
321+
Then the result should be 120
322+
"""
323+
When I invoke the "Auto Format Document" command without waiting for the tag changes
324+
Then the editor should be updated to
325+
"""
326+
Feature: Addition
327+
328+
Scenario: Add two numbers
329+
Given I have entered 50 into the calculator
330+
And I have entered 70 into the calculator
331+
When I add them
332+
And I check the result
333+
Then there should be no error
334+
And the result should be 120
304335
"""

0 commit comments

Comments
 (0)