private static TextSpan GetSyntaxSpan(SyntaxTrivia trivia, SyntaxToken token, SyntaxNode node, TextSpan selection) { TextSpan finalSpan; int start = selection.Start; int end = selection.End; if (trivia.RawKind != 0) // in trivia { if (IsOverlap(trivia.Span, start, end) && (trivia.RawKind == 8542 || trivia.RawKind == 8541)) // in comment so grab comment { finalSpan = trivia.Span; } else // not a comment or already selecting comment so get selection of next open/close bracket { TextSpan innerBracketSpan = GetInnerBracketSpan(node); while ((innerBracketSpan.Equals(node.Span) && node.Parent != null) || !IsOverlap(innerBracketSpan, start, end)) { node = node.Parent; innerBracketSpan = GetInnerBracketSpan(node); } // check that we are not selecting same area as current selection finalSpan = (innerBracketSpan.Equals(selection)) ? node.Span : innerBracketSpan; } } else if (IsOverlap(token.Span, start, end)) // in token. { finalSpan = token.Span; } else // in node { node = (IsOverlap(node, start, end) || node.Parent == null) ? node : node.Parent; TextSpan innerBracketSpan = GetInnerBracketSpan(node); while ((innerBracketSpan.Equals(node.Span) && node.Parent != null) || !IsOverlap(innerBracketSpan, start, end)) { if (IsOverlap(node.Parent.Span, start, end) && GetInnerBracketSpan(node.Parent).Equals(node.Parent.Span)) { return(node.Span); } node = node.Parent; innerBracketSpan = GetInnerBracketSpan(node); } if (IsOverlap(innerBracketSpan, start, end)) { finalSpan = innerBracketSpan; } else { finalSpan = node.Span; } } return(finalSpan); }
public void TextSpanEquality00() { TextSpan span1 = new TextSpan(0, 10); TextSpan span2 = new TextSpan(0, 10); Assert.True(span1.Equals(span2)); Assert.NotEqual(default, span1);
private void AddWordSpan(TextSpan selection) { TextSpan[] spans = new TextSpan[1]; // HACK: have seen 4 as usual flags value for GetWordExtent ;) uint flags = 4; GetWordExtent(selection.iStartLine, selection.iStartIndex, flags, spans); TextSpan wordSpan = spans[0]; GetWordExtent(selection.iEndLine, selection.iEndIndex, flags, spans); TextSpan wordSpanOther = spans[0]; // in principle, selectionsStack contains at least the whole file location if (wordSpan.Equals(wordSpanOther) && _selectionsStack != null && _selectionsStack.Count > 0) { Location last = _selectionsStack[_selectionsStack.Count - 1]; Location word = Utils.LocationFromSpan(last.FileIndex, wordSpan); if (last.StrictlyContains(word) && last != word) { _selectionsStack.Add(word); } } else { _selectionsStack = new List <Location>(); _selectionsStack.Add(Utils.LocationFromSpan(0, wordSpan)); } }
public void TextSpanEquality01() { TextSpan span1 = new TextSpan(0, 10); TextSpan span2 = new TextSpan(0, 11); TextSpan span3 = new TextSpan(1, 11); Assert.False(span1.Equals(span2)); Assert.False(span1.Equals(span3)); Assert.False(span2.Equals(span3)); Assert.True(span1 != span2, span1.ToString() + " : " + span2.ToString()); Assert.True(span1 != span3, span1.ToString() + " : " + span3.ToString()); Assert.True(span2 != span3, span2.ToString() + " : " + span3.ToString()); Assert.False(span1 == span2, span1.ToString() + " : " + span2.ToString()); Assert.NotEqual <object>(new string('a', 3), span1); }
public SeparatedSyntaxList(IEnumerable <SyntaxBase> elements, IEnumerable <SyntaxBase> separators, TextSpan span) { this.Elements = elements.ToImmutableArray(); this.Separators = separators.ToImmutableArray(); this.Span = span; if (this.Elements.Any()) { if (this.Elements.Length != this.Separators.Length && this.Elements.Length != (this.Separators.Length + 1)) { throw new ArgumentException($"The number of separators ({this.Separators.Length}) must be the same or one less than the number of elements ({this.Elements.Length})."); } // with one or more elements, the span should be from the beginning of the first element to the end of the last element var expectedSpan = TextSpan.Between(this.Elements.First().Span, this.Elements.Last().Span); if (span.Equals(expectedSpan) == false) { throw new ArgumentException($"The specified span '{span}' must be from the beginning of the first element (inclusive) to the end of the last element (exclusive). Expected span '{expectedSpan}'."); } } else { if (this.Separators.Length != 0) { throw new ArgumentException("With zero elements, the number of separators must also be zero."); } if (span.Length != 0) { throw new ArgumentException($"The specified span was '{span}' but expected a zero-length span."); } } }
public bool Equals(DeclaredSymbolInfo other) => Name == other.Name && NameSuffix == other.NameSuffix && ContainerDisplayName == other.ContainerDisplayName && FullyQualifiedContainerName == other.FullyQualifiedContainerName && Span.Equals(other.Span) && _flags == other._flags && InheritanceNames.SequenceEqual(other.InheritanceNames, arg: true, (s1, s2, _) => s1 == s2);
public bool Equals(RelatedLocation other) { return(ConflictCheckSpan.Equals(other.ConflictCheckSpan) && Type == other.Type && IsReference == other.IsReference && EqualityComparer <DocumentId> .Default.Equals(DocumentId, other.DocumentId) && ComplexifiedTargetSpan.Equals(other.ComplexifiedTargetSpan)); }
public void Equals3() { var s1 = new TextSpan(1, 5); var s2 = new TextSpan(1, 40); Assert.False(s1.Equals(s2), s1.ToString() + " : " + s2.ToString()); Assert.False(s1 == s2, s1.ToString() + " : " + s2.ToString()); Assert.True(s1 != s2, s1.ToString() + " : " + s2.ToString()); Assert.NotEqual(s1, s2); }
public void Equals3() { var s1 = new TextSpan(1, 5); var s2 = new TextSpan(1, 40); Assert.False(s1.Equals(s2), s1.ToString() + " : " + s2.ToString()); Assert.False(s1 == s2, s1.ToString() + " : " + s2.ToString()); Assert.True(s1 != s2, s1.ToString() + " : " + s2.ToString()); Assert.NotEqual(s1, s2); }
public void TextSpanEquality00() { TextSpan span1 = new TextSpan(0, 10); TextSpan span2 = new TextSpan(0, 10); Assert.True(span1.Equals(span2)); Assert.True(span1 == span2, span1.ToString() + " : " + span2.ToString()); Assert.False(span1 != span2, span1.ToString() + " : " + span2.ToString()); Assert.True(span2.Equals(span1)); Assert.True(span2 == span1, span2.ToString() + " : " + span1.ToString()); Assert.False(span2 != span1, span2.ToString() + " : " + span1.ToString()); }
public void TextSpanEquality01() { TextSpan span1 = new TextSpan(0, 10); TextSpan span2 = new TextSpan(0, 11); TextSpan span3 = new TextSpan(1, 11); Assert.False(span1.Equals(span2)); Assert.False(span1.Equals(span3)); Assert.False(span2.Equals(span3)); Assert.True(span1 != span2, span1.ToString() + " : " + span2.ToString()); Assert.True(span1 != span3, span1.ToString() + " : " + span3.ToString()); Assert.True(span2 != span3, span2.ToString() + " : " + span3.ToString()); Assert.False(span1 == span2, span1.ToString() + " : " + span2.ToString()); Assert.NotEqual<object>(new string ('a', 3), span1); }
public void TextSpanEquality00() { TextSpan span1 = new TextSpan(0, 10); TextSpan span2 = new TextSpan(0, 10); Assert.True(span1.Equals(span2)); Assert.NotNull(span1); Assert.True(span1 == span2, span1.ToString() + " : " + span2.ToString()); Assert.False(span1 != span2, span1.ToString() + " : " + span2.ToString()); Assert.True(span2.Equals(span1)); Assert.NotNull(span2); Assert.True(span2 == span1, span2.ToString() + " : " + span1.ToString()); Assert.False(span2 != span1, span2.ToString() + " : " + span1.ToString()); }
public bool Equals(EmbeddedDiagnostic other) => Message == other.Message && Span.Equals(other.Span);