Skip to content

Commit

Permalink
Add FormatDocument command for feature files (#61)
Browse files Browse the repository at this point in the history
* Add basic FormatDocument command support. (Cherry picked from @Dreamescaper with commit 66403f2)

* Included missing FormatDocumentCommand.cs file in TechTalk.SpecFlow.VsIntegration project

* Added configuration settings for the FormatDocumentCommand

* Replaced '\n' with Environment.NewLine to preserve configured line-endings when formatting a feature file

* Formatted using space instead of tabs

* Move FormatDocumentCommand class to VsIntegration.Implementation project

* fix tables formatting and cursor jumping

* add options to UI + small fixes

* Change index names
  • Loading branch information
littlegenius666 authored and SabotageAndi committed May 7, 2019
1 parent 4ec3550 commit abbc496
Show file tree
Hide file tree
Showing 7 changed files with 469 additions and 6 deletions.
10 changes: 10 additions & 0 deletions IdeIntegration/Options/IntegrationOptions.cs
Expand Up @@ -18,6 +18,16 @@ public class IntegrationOptions
public string CodeBehindFileGeneratorExchangePath { get; set; }
public bool LegacyEnableSpecFlowSingleFileGeneratorCustomTool { get; set; }
public bool OptOutDataCollection { get; set; }
public bool NormalizeLineBreaks { get; set; }
public int LineBreaksBeforeScenario { get; set; }
public int LineBreaksBeforeExamples { get; set; }
public bool UseTabsForIndent { get; set; }
public int FeatureIndent { get; set; }
public int ScenarioIndent { get; set; }
public int StepIndent { get; set; }
public int TableIndent { get; set; }
public int MultilineIndent { get; set; }
public int ExampleIndent { get; set; }
}

public enum GenerationMode
Expand Down
Expand Up @@ -57,7 +57,17 @@ private static IntegrationOptions GetOptions(DTE dte)
GenerationMode = GetGeneralOption(dte, "GenerationMode", OptionDefaultValues.GenerationModeDefaultValue),
CodeBehindFileGeneratorPath = GetGeneralOption(dte, "PathToCodeBehindGeneratorExe", OptionDefaultValues.CodeBehindFileGeneratorPath),
CodeBehindFileGeneratorExchangePath = GetGeneralOption(dte, "CodeBehindFileGeneratorExchangePath", OptionDefaultValues.CodeBehindFileGeneratorExchangePath),
OptOutDataCollection = GetGeneralOption(dte, "OptOutDataCollection", OptionDefaultValues.DefaultOptOutDataCollection)
OptOutDataCollection = GetGeneralOption(dte, "OptOutDataCollection", OptionDefaultValues.DefaultOptOutDataCollection),
NormalizeLineBreaks = GetGeneralOption(dte, "NormalizeLineBreaks", OptionDefaultValues.NormalizeLineBreaksDefaultValue),
LineBreaksBeforeScenario = GetGeneralOption(dte, "LineBreaksBeforeScenario", OptionDefaultValues.DefaultLineBreaksBeforeScenario),
LineBreaksBeforeExamples = GetGeneralOption(dte, "LineBreaksBeforeExamples", OptionDefaultValues.DefaultLineBreaksBeforeExamples),
UseTabsForIndent = GetGeneralOption(dte, "UseTabsForIndent", OptionDefaultValues.UseTabsForIndentDefaultValue),
FeatureIndent = GetGeneralOption(dte, "FeatureIndent", OptionDefaultValues.DefaultFeatureIndent),
ScenarioIndent = GetGeneralOption(dte, "ScenarioIndent", OptionDefaultValues.DefaultScenarioIndent),
StepIndent = GetGeneralOption(dte, "StepIndent", OptionDefaultValues.DefaultStepIndent),
TableIndent = GetGeneralOption(dte, "TableIndent", OptionDefaultValues.DefaultTableIndent),
MultilineIndent = GetGeneralOption(dte, "MultilineIndent", OptionDefaultValues.DefaultMultilineIndent),
ExampleIndent = GetGeneralOption(dte, "ExampleIndent", OptionDefaultValues.DefaultExampleIndent)
};
cachedOptions = options;
return options;
Expand Down
Expand Up @@ -17,13 +17,15 @@ public class EditorCommandFilter
private readonly FormatTableCommand formatTableCommand;
private readonly CommentUncommentCommand commentUncommentCommand;
private readonly RenameCommand renameCommand;
private readonly FormatDocumentCommand formatDocumentCommand;

public EditorCommandFilter(IIdeTracer tracer, IGoToStepDefinitionCommand goToStepDefinitionCommand, FormatTableCommand formatTableCommand, CommentUncommentCommand commentUncommentCommand, RenameCommand renameCommand)
public EditorCommandFilter(IIdeTracer tracer, IGoToStepDefinitionCommand goToStepDefinitionCommand, FormatTableCommand formatTableCommand, CommentUncommentCommand commentUncommentCommand, RenameCommand renameCommand, FormatDocumentCommand formatDocumentCommand)
{
this.goToStepDefinitionCommand = goToStepDefinitionCommand;
this.formatTableCommand = formatTableCommand;
this.commentUncommentCommand = commentUncommentCommand;
this.renameCommand = renameCommand;
this.formatDocumentCommand = formatDocumentCommand;
this.tracer = tracer;
}

Expand Down Expand Up @@ -61,6 +63,7 @@ public bool QueryStatus(GherkinEditorContext editorContext, Guid pguidCmdGroup,
case VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK:
case VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK:
case VSConstants.VSStd2KCmdID.RENAME:
case VSConstants.VSStd2KCmdID.FORMATDOCUMENT:
return true;
}
}
Expand Down Expand Up @@ -145,6 +148,10 @@ public bool PreExec(GherkinEditorContext editorContext, Guid pguidCmdGroup, uint
if (renameCommand.Rename(editorContext))
return true;
break;
case VSConstants.VSStd2KCmdID.FORMATDOCUMENT:
if (formatDocumentCommand.FormatDocument(editorContext))
return true;
break;
}
}
else if (pguidCmdGroup == GuidList.guidSpecFlowCmdSet)
Expand Down

0 comments on commit abbc496

Please sign in to comment.