void ReParse() { try { var newSnapshot = _buffer.CurrentSnapshot; var textSnapshotLines = newSnapshot.Lines.ToList(); var data = new RegionParserData { TextSnapshotLines = textSnapshotLines }; RegionParser.Parse(data); var newRegions = data.Regions; //determine the changed span, and send a changed event with the new spans var oldSpans = new List <Span>(_regions.Select(r => AsSnapshotSpan(r, _snapshot) .TranslateTo(newSnapshot, SpanTrackingMode.EdgeExclusive) .Span)); var newSpans = new List <Span>(newRegions.Select(r => AsSnapshotSpan(r, newSnapshot).Span)); var oldSpanCollection = new NormalizedSpanCollection(oldSpans); var newSpanCollection = new NormalizedSpanCollection(newSpans); //the changed regions are regions that appear in one set or the other, but not both. var removed = NormalizedSpanCollection.Difference(oldSpanCollection, newSpanCollection); var changeStart = int.MaxValue; var changeEnd = -1; if (removed.Count > 0) { changeStart = removed[0].Start; changeEnd = removed[removed.Count - 1].End; } if (newSpans.Count > 0) { changeStart = Math.Min(changeStart, newSpans[0].Start); changeEnd = Math.Max(changeEnd, newSpans[newSpans.Count - 1].End); } _snapshot = newSnapshot; _regions = newRegions; if (changeStart <= changeEnd) { TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(_snapshot, Span.FromBounds(changeStart, changeEnd)))); } } catch (Exception e) { Log.Push(e); } }
public static void Parse(RegionParserData data) { var lineCount = data.LineCount; for (var i = 0; i < lineCount; i++) { if (i + 4 >= lineCount) { continue; } var nextLineText = data[i + 1]?.Replace(" ", string.Empty); var isResponseCheck = nextLineText?.StartsWith("if(!") == true && nextLineText.EndsWith(".Success)"); var LineNumber = data.GetLineNumber(i); if (isResponseCheck) { //var response = bo.call(); //if (!response.Success) //{ // return returnObject.Add(response); -> var x = bo.call(); //} // var x = response.Value; var leftBracketOffset = 2; if (data[i + leftBracketOffset]?.Trim() != "{") { continue; } var rightBracketOffset = 4; // returnObject.Results.AddRange(responseAcc.Results); if (IsAddingResultToReturnObject(data[i + leftBracketOffset + 1]) && data[i + leftBracketOffset + 2]?.Trim() == "return returnObject;" && data[i + leftBracketOffset + 3]?.Trim() == "}") { rightBracketOffset = leftBracketOffset + 3; } else if (data[i + leftBracketOffset + 1]?.Trim().StartsWith("return returnObject") == true && data[i + leftBracketOffset + 2]?.Trim() == "}") { rightBracketOffset = leftBracketOffset + 2; } else if (data[i + leftBracketOffset + 1]?.Trim().StartsWith("Context.AddResult(") == true && data[i + leftBracketOffset + 2]?.Trim() == "return;" && data[i + leftBracketOffset + 3]?.Trim() == "}") { rightBracketOffset = leftBracketOffset + 3; } else { continue; } var firstChar = data[i + 1].First(c => c != ' '); var firstCharIndex = data[i + 1].IndexOf(firstChar); var currentLine = data[i]; var currentLineAsAssignmentLine = VariableAssignmentLine.Parse(currentLine); if (currentLineAsAssignmentLine == null) { continue; } VariableAssignmentLine responseValueAssignmentToAnotherVariable = null; // walk empty lines var endOfEmptyLinesOffset = rightBracketOffset + 1; if (rightBracketOffset < lineCount - 1) { while (true) { if (i + endOfEmptyLinesOffset >= lineCount) { break; } if (!string.IsNullOrEmpty(data[i + endOfEmptyLinesOffset])) { break; } endOfEmptyLinesOffset++; } responseValueAssignmentToAnotherVariable = VariableAssignmentLine.Parse(data[i + endOfEmptyLinesOffset]); } if (responseValueAssignmentToAnotherVariable != null && VariableAssignmentLine.IsResponseValueMatch(currentLineAsAssignmentLine, responseValueAssignmentToAnotherVariable)) { var sb = new StringBuilder(); if (responseValueAssignmentToAnotherVariable.VariableTypeName != null) { sb.Append(responseValueAssignmentToAnotherVariable.VariableTypeName); sb.Append(" "); } sb.Append(responseValueAssignmentToAnotherVariable.VariableName); sb.Append(" = "); sb.Append(currentLineAsAssignmentLine.AssignedValue); sb.Append(";"); data.Regions.Add(new Region { StartLine = LineNumber, StartOffset = firstCharIndex, EndLine = data.GetLineNumber(i + endOfEmptyLinesOffset), Text = sb.ToString() }); i = i + endOfEmptyLinesOffset; continue; } data.Regions.Add(new Region { StartLine = LineNumber, StartOffset = firstCharIndex, EndLine = data.GetLineNumber(i + rightBracketOffset), Text = currentLineAsAssignmentLine.AssignedValue + ";" }); i = i + rightBracketOffset; } } }