/// <summary> /// Returns true if the symbol of element <paramref name="element"/> /// is equal to <paramref name="symbol"/> /// </summary> private static bool AreSymbolsEqual(Symbol symbol, SyntaxElement element, FindRelatedOptions options) { var canSee = (options & FindRelatedOptions.SeeThroughVariables) != 0; return((element is NameReference n && (n.ReferencedSymbol == symbol || (canSee && n.ReferencedSymbol == Symbol.GetExpressionResultType(symbol)))) || (element is NameDeclaration d && (d.ReferencedSymbol == symbol || (canSee && Symbol.GetExpressionResultType(d.ReferencedSymbol) == symbol)))); }
public override RelatedInfo GetRelatedElements(int position, FindRelatedOptions options, CancellationToken cancellationToken) { var result = _service.GetRelatedElements(position - _offset, options, cancellationToken); if (result.Elements.Count > 0 && _offset > 0) { return(new RelatedInfo(result.Elements.Select(e => new RelatedElement(e.Start + _offset, e.Length, e.Kind, e.CursorLeft + _offset, e.CursorRight + _offset)).ToReadOnly(), result.CurrentIndex)); } else { return(result); } }
public override RelatedInfo GetRelatedElements(int position, FindRelatedOptions options = FindRelatedOptions.None, CancellationToken cancellationToken = default(CancellationToken)) { if (this.TryGetBoundCode(cancellationToken, true, out var code)) { try { return(new KustoRelatedElementFinder(code).FindRelatedElements(position, options)); } catch (Exception) { } } return(RelatedInfo.Empty); }
public RelatedInfo FindRelatedElements(int position, FindRelatedOptions options = FindRelatedOptions.None) { var token = _code.Syntax.GetTokenAt(position); if (token == null || position > token.TriviaStart && position < token.TextStart - 1) { // position is inside trivia and not attached to any token. return(RelatedInfo.Empty); } var prev = token?.GetPreviousToken(); if (position == token.TriviaStart) { if (token.Trivia.Length > 0 || (prev != null && IsRelatable(prev) && !IsRelatable(token))) { token = token.GetPreviousToken(); } } if (token == null) { return(RelatedInfo.Empty); } var elements = new List <RelatedElement>(); if (IsBracket(token)) { GetRelatedBrackets(token, elements); } else if (IsPartOfNameReferenceOrDeclaration(token)) { GetRelatedNameReferencesAndDeclarations(token, elements, options); } if (elements.Count > 1) { var current = elements.FirstOrDefault(r => r.Start == token.TextStart); if (current != null) { var currentIndex = elements.IndexOf(current); return(new RelatedInfo(elements, currentIndex)); } } return(RelatedInfo.Empty); }
public void GetRelatedNameReferencesAndDeclarations(SyntaxToken token, List <RelatedElement> elements, FindRelatedOptions options) { var symbol = token.Parent.GetFirstAncestorOrSelf <SyntaxNode>(n => n.ReferencedSymbol != null)?.ReferencedSymbol; if (symbol != null) { _code.Syntax.WalkElements(e => { if (AreSymbolsEqual(symbol, e, options)) { RelatedElementKind kind; if (e is NameDeclaration) { kind = RelatedElementKind.Declaration; } else if (e is NameReference) { kind = RelatedElementKind.Reference; } else { kind = RelatedElementKind.Other; } elements.Add(new RelatedElement(e.TextStart, e.Width, kind, e.TextStart, e.TextStart)); } }); } }
public override RelatedInfo GetRelatedElements(int position, FindRelatedOptions options, CancellationToken cancellationToken) { return(RelatedInfo.Empty); }
/// <summary> /// Gets a list of all the syntax elements related to the syntax element at or adjacent to the text position. /// </summary> public abstract RelatedInfo GetRelatedElements(int position, FindRelatedOptions options = FindRelatedOptions.None, CancellationToken cancellationToken = default(CancellationToken));