private void JumpToStep(StepInstanceWithProjectScope stepInstanceWithProjectScope) { var position = ((ISourceFilePosition)stepInstanceWithProjectScope.StepInstance); var featureProjItem = VsxHelper.GetAllPhysicalFileProjectItem(stepInstanceWithProjectScope.ProjectScope.Project).FirstOrDefault( pi => VsxHelper.GetProjectRelativePath(pi).Equals(position.SourceFile)); if (featureProjItem == null) { return; } if (!featureProjItem.IsOpen) { featureProjItem.Open(); } GoToLine(featureProjItem, position.FilePosition.Line); }
private static Document JumpToStep(StepInstanceWithProjectScope stepInstance) { var sourceFilePosition = ((ISourceFilePosition)stepInstance.StepInstance); var featureFile = VsxHelper.GetAllPhysicalFileProjectItem(stepInstance.ProjectScope.Project).FirstOrDefault( pi => VsxHelper.GetProjectRelativePath(pi).Equals(sourceFilePosition.SourceFile)); if (featureFile == null) { return(null); } if (!featureFile.IsOpen) { featureFile.Open(); } GoToLine(featureFile, sourceFilePosition.FilePosition.Line); return(featureFile.Document); }
private void RenameStep(StepInstanceWithProjectScope stepInstance, string newStepRegex, IStepDefinitionBinding binding) { var featureFileDocument = JumpToStep(stepInstance); if (featureFileDocument == null) { return; } var stepEditorContext = GherkinEditorContext.FromDocument(featureFileDocument, _gherkinLanguageServiceFactory); var stepToRename = GetCurrentStep(stepEditorContext); if (stepToRename == null) { return; } if (!binding.Regex.IsMatch(stepToRename.Text)) { return; } var stepLineStart = stepEditorContext.TextView.Selection.Start.Position.GetContainingLine(); using (var stepNameTextEdit = stepLineStart.Snapshot.TextBuffer.CreateEdit()) { var line = stepLineStart.Snapshot.GetLineFromLineNumber(stepLineStart.LineNumber); var lineText = line.GetText(); var trimmedText = lineText.Trim(); var numLeadingWhiteSpaces = lineText.Length - trimmedText.Length; var actualStepName = trimmedText.Substring(stepToRename.Keyword.Length); var newStepName = BuildStepNameWithNewRegex(actualStepName, newStepRegex, binding); var stepNamePosition = line.Start.Position + numLeadingWhiteSpaces + stepToRename.Keyword.Length; stepNameTextEdit.Replace(stepNamePosition, actualStepName.Length, newStepName); stepNameTextEdit.Apply(); } }
private string GetStepInstanceGotoTitle(StepInstanceWithProjectScope stepInstanceWithProjectScope) { var stepInstance = stepInstanceWithProjectScope.StepInstance; return(stepInstance.GetFileScopedLabel()); }