Browse files

add options do disable step match coloring + fixes

  • Loading branch information...
1 parent 0e72961 commit 43f8b8012d2683b10a04a46e850eb8555cc726b6 @gasparnagy gasparnagy committed Jul 27, 2012
View
1 IdeIntegration/IdeIntegration/Options/IntegrationOptions.cs
@@ -7,6 +7,7 @@ public class IntegrationOptions
public bool EnableIntelliSense { get; set; }
public bool EnableAnalysis { get; set; }
public bool EnableTableAutoFormat { get; set; }
+ public bool EnableStepMatchColoring { get; set; }
public bool EnableTracing { get; set; }
public string TracingCategories { get; set; }
public TestRunnerTool TestRunnerTool { get; set; }
View
12 IdeIntegration/Vs2010Integration/LanguageService/GherkinLanguageService.cs
@@ -14,6 +14,7 @@ public class GherkinLanguageService : IDisposable
{
private readonly IProjectScope projectScope;
private readonly IVisualStudioTracer visualStudioTracer;
+ private readonly bool enableStepMatchColoring;
private bool isDisposed = false;
private IGherkinFileScope lastGherkinFileScope = null;
@@ -26,10 +27,11 @@ public IProjectScope ProjectScope
get { return projectScope; }
}
- public GherkinLanguageService(IProjectScope projectScope, IVisualStudioTracer visualStudioTracer)
+ public GherkinLanguageService(IProjectScope projectScope, IVisualStudioTracer visualStudioTracer, bool enableStepMatchColoring)
{
this.projectScope = projectScope;
this.visualStudioTracer = visualStudioTracer;
+ this.enableStepMatchColoring = enableStepMatchColoring;
AnalyzingEnabled = projectScope.GherkinScopeAnalyzer != null;
visualStudioTracer.Trace("Language service created", "GherkinLanguageService");
@@ -56,8 +58,12 @@ private void Initialize(ITextBuffer textBuffer)
TextBufferChanged(GherkinTextBufferChange.CreateEntireBufferChange(textBuffer.CurrentSnapshot));
projectScope.GherkinDialectServicesChanged += ReParseEntireFile;
- projectScope.StepSuggestionProvider.Ready += ReParseEntireFile;
- projectScope.StepSuggestionProvider.BindingsChanged += ReParseEntireFile;
+
+ if (enableStepMatchColoring)
+ {
+ projectScope.StepSuggestionProvider.Ready += ReParseEntireFile;
+ projectScope.StepSuggestionProvider.BindingsChanged += ReParseEntireFile;
+ }
}
private void ReParseEntireFile()
View
6 IdeIntegration/Vs2010Integration/LanguageService/GherkinLanguageServiceFactory.cs
@@ -4,6 +4,7 @@
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text;
+using TechTalk.SpecFlow.IdeIntegration.Options;
using TechTalk.SpecFlow.Vs2010Integration.Tracing;
using TechTalk.SpecFlow.Vs2010Integration.Utils;
@@ -32,6 +33,9 @@ internal class GherkinLanguageServiceFactory : IGherkinLanguageServiceFactory
[Import]
internal IGherkinBufferServiceManager GherkinBufferServiceManager = null;
+ [Import]
+ IIntegrationOptionsProvider IntegrationOptionsProvider = null;
+
public GherkinLanguageService GetLanguageService(ITextBuffer textBuffer)
{
var gherkinLanguageService = GherkinBufferServiceManager.GetOrCreate(textBuffer, () => CreateLanguageService(textBuffer));
@@ -43,7 +47,7 @@ private GherkinLanguageService CreateLanguageService(ITextBuffer textBuffer)
{
var project = VsxHelper.GetCurrentProject(textBuffer, AdaptersFactory, ServiceProvider);
var projectScope = ProjectScopeFactory.GetProjectScope(project);
- var languageService = new GherkinLanguageService(projectScope, VisualStudioTracer);
+ var languageService = new GherkinLanguageService(projectScope, VisualStudioTracer, enableStepMatchColoring: IntegrationOptionsProvider.GetOptions().EnableStepMatchColoring);
textBuffer.Changed +=
(sender, args) => languageService.TextBufferChanged(GetTextBufferChange(args));
View
50 IdeIntegration/Vs2010Integration/LanguageService/GherkinTextBufferParserListener.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.VisualStudio.Text;
@@ -29,6 +28,7 @@ internal abstract class GherkinTextBufferParserListenerBase : IGherkinListener
private readonly GherkinFileEditorClassifications classifications;
private readonly GherkinFileScope gherkinFileScope;
private readonly IProjectScope projectScope;
+ private readonly bool enableStepMatchColoring;
private GherkinBuffer gherkinBuffer;
private readonly ITextSnapshot textSnapshot;
@@ -55,6 +55,7 @@ protected GherkinTextBufferParserListenerBase(GherkinDialect gherkinDialect, ITe
this.textSnapshot = textSnapshot;
this.classifications = projectScope.Classifications;
this.projectScope = projectScope;
+ this.enableStepMatchColoring = projectScope.IntegrationOptionsProvider.GetOptions().EnableStepMatchColoring;
gherkinFileScope = new GherkinFileScope(gherkinDialect, textSnapshot);
}
@@ -98,16 +99,17 @@ private void ColorizeSpan(GherkinBufferSpan span, IClassificationType classifica
AddClassification(classificationType, startIndex, length);
}
- private void ColorizeLinePart(string value, GherkinBufferSpan span, IClassificationType classificationType)
+ private int ColorizeLinePart(string value, GherkinBufferSpan span, IClassificationType classificationType, int lineStartPosition = 0)
{
- var textPosition = gherkinBuffer.IndexOfTextForLine(value, span.StartPosition.Line);
+ var textPosition = gherkinBuffer.IndexOfTextForLine(value, span.StartPosition.Line, lineStartPosition);
if (textPosition == null)
- return;
+ return lineStartPosition;
var textSpan = new GherkinBufferSpan(
textPosition,
textPosition.ShiftByCharacters(value.Length));
ColorizeSpan(textSpan, classificationType);
+ return textPosition.LinePosition + value.Length;
}
private void RegisterKeyword(string keyword, GherkinBufferSpan headerSpan)
@@ -328,53 +330,47 @@ public void ExamplesTag(string name, GherkinBufferSpan tagSpan)
}
private static readonly Regex placeholderRe = new Regex(@"\<.*?\>");
+
public void Step(string keyword, StepKeyword stepKeyword, Parser.Gherkin.ScenarioBlock scenarioBlock, string text, GherkinBufferSpan stepSpan)
{
- if (CurrentFileBlockBuilder.BlockType == typeof(IScenarioOutlineBlock))
- {
- var matches = placeholderRe.Matches(text);
- foreach (Match match in matches)
- ColorizeLinePart(match.Value, stepSpan, classifications.Placeholder);
- }
-
var editorLine = stepSpan.StartPosition.Line;
var tags = FeatureTags.Concat(CurrentFileBlockBuilder.Tags).Distinct();
var stepContext = new StepContext(FeatureTitle, CurrentFileBlockBuilder.BlockType == typeof(IBackgroundBlock) ? null : CurrentFileBlockBuilder.Title, tags.ToArray(), gherkinFileScope.GherkinDialect.CultureInfo);
currentStep = new GherkinStep((StepDefinitionType)scenarioBlock, (StepDefinitionKeyword)stepKeyword, text, stepContext, keyword, editorLine - CurrentFileBlockBuilder.KeywordLine);
CurrentFileBlockBuilder.Steps.Add(currentStep);
-
-
var bindingMatchService = projectScope.BindingMatchService;
-
-
-
- if (bindingMatchService.Ready && bindingMatchService != null)
+ if (enableStepMatchColoring && bindingMatchService != null && bindingMatchService.Ready)
{
List<BindingMatch> candidatingMatches;
- candidatingMatches = null;
StepDefinitionAmbiguityReason ambiguityReason;
- CultureInfo bindingCulture = currentStep.StepContext.Language;
+ CultureInfo bindingCulture = projectScope.SpecFlowProjectConfiguration.RuntimeConfiguration.BindingCulture ?? currentStep.StepContext.Language;
var match = bindingMatchService.GetBestMatch(currentStep, bindingCulture, out ambiguityReason, out candidatingMatches);
- if (candidatingMatches.Count == 0)
+ if (match.Success)
{
- ColorizeKeywordLine(keyword, stepSpan, classifications.StepText);
+ ColorizeKeywordLine(keyword, stepSpan, classifications.KnownStepText);
+ int linePos = stepSpan.StartPosition.LinePosition;
+ foreach (var stringArg in match.Arguments.OfType<string>())
+ {
+ linePos = ColorizeLinePart(stringArg, stepSpan, classifications.Variable, linePos);
+ }
}
else
{
- ColorizeKeywordLine(keyword, stepSpan, classifications.KnownStepText);
- foreach (String value in candidatingMatches.First().StepBinding.Regex.Split(text))
- ColorizeLinePart(value, stepSpan, classifications.Variable);
+ ColorizeKeywordLine(keyword, stepSpan, classifications.StepText);
}
-
-
-
}
else
ColorizeKeywordLine(keyword, stepSpan, classifications.StepText);
+ if (CurrentFileBlockBuilder.BlockType == typeof(IScenarioOutlineBlock))
+ {
+ var matches = placeholderRe.Matches(text);
+ foreach (Match match in matches)
+ ColorizeLinePart(match.Value, stepSpan, classifications.Placeholder);
+ }
}
public void TableHeader(string[] cells, GherkinBufferSpan rowSpan, GherkinBufferSpan[] cellSpans)
View
2 IdeIntegration/Vs2010Integration/Options/IntegrationOptionsProvider.cs
@@ -19,6 +19,7 @@ internal class IntegrationOptionsProvider : IIntegrationOptionsProvider
public const bool EnableIntelliSenseDefaultValue = true;
public const bool EnableAnalysisDefaultValue = true;
public const bool EnableTableAutoFormatDefaultValue = true;
+ public const bool EnableStepMatchColoringDefaultValue = true;
public const bool EnableTracingDefaultValue = false;
public const string TracingCategoriesDefaultValue = "all";
public const TestRunnerTool TestRunnerToolDefaultValue = TestRunnerTool.Auto;
@@ -48,6 +49,7 @@ private static IntegrationOptions GetOptions(DTE dte)
EnableIntelliSense = GetGeneralOption(dte, "EnableIntelliSense", EnableIntelliSenseDefaultValue),
EnableAnalysis = GetGeneralOption(dte, "EnableAnalysis", EnableAnalysisDefaultValue),
EnableTableAutoFormat = GetGeneralOption(dte, "EnableTableAutoFormat", EnableTableAutoFormatDefaultValue),
+ EnableStepMatchColoring = GetGeneralOption(dte, "EnableStepMatchColoring", EnableStepMatchColoringDefaultValue),
EnableTracing = GetGeneralOption(dte, "EnableTracing", EnableTracingDefaultValue),
TracingCategories = GetGeneralOption(dte, "TracingCategories", TracingCategoriesDefaultValue),
TestRunnerTool = GetGeneralOption(dte, "TestRunnerTool", TestRunnerToolDefaultValue),
View
7 IdeIntegration/Vs2010Integration/Options/OptionsPageGeneral.cs
@@ -55,6 +55,12 @@ public bool EnableSyntaxColoring
public bool EnableIntelliSense { get; set; }
[Category("Editor Settings")]
+ [Description("Controls whether the step definition match status should be indicated with a different color in the editor. (beta)")]
+ [DisplayName(@"Enable Step Match Coloring")]
+ [DefaultValue(IntegrationOptionsProvider.EnableStepMatchColoringDefaultValue)]
+ public bool EnableStepMatchColoring { get; set; }
+
+ [Category("Editor Settings")]
[Description("Controls whether the tables should be formatted automatically when you type \"|\" character.")]
[DisplayName(@"Enable Table Formatting")]
[DefaultValue(IntegrationOptionsProvider.EnableTableAutoFormatDefaultValue)]
@@ -85,6 +91,7 @@ public OptionsPageGeneral()
EnableOutlining = IntegrationOptionsProvider.EnableOutliningDefaultValue;
EnableIntelliSense = IntegrationOptionsProvider.EnableIntelliSenseDefaultValue;
EnableTableAutoFormat = IntegrationOptionsProvider.EnableTableAutoFormatDefaultValue;
+ EnableStepMatchColoring = IntegrationOptionsProvider.EnableStepMatchColoringDefaultValue;
EnableTracing = IntegrationOptionsProvider.EnableTracingDefaultValue;
TracingCategories = IntegrationOptionsProvider.TracingCategoriesDefaultValue;
TestRunnerTool = IntegrationOptionsProvider.TestRunnerToolDefaultValue;
View
12 Parser/Gherkin/GherkinBuffer.cs
@@ -142,12 +142,18 @@ public GherkinBufferPosition GetMatchForLine(Regex regex, int line)
public GherkinBufferPosition IndexOfTextForLine(string text, int line)
{
- int startPosition = GetBufferPositionFromLine(line);
+ return IndexOfTextForLine(text, line, 0);
+ }
+
+ public GherkinBufferPosition IndexOfTextForLine(string text, int line, int skipLineCharacters)
+ {
+ int lineStartPosition = GetBufferPositionFromLine(line);
+ int startPosition = lineStartPosition + skipLineCharacters;
int length = GetLineLength(line);
- var index = content.IndexOf(text, startPosition, length);
+ var index = content.IndexOf(text, startPosition, length - skipLineCharacters, StringComparison.InvariantCulture);
if (index < 0)
return null;
- return new GherkinBufferPosition(this, line, index - startPosition);
+ return new GherkinBufferPosition(this, line, index - lineStartPosition);
}
public string GetContent()

0 comments on commit 43f8b80

Please sign in to comment.