protected override TextSpan?CreateTargetSpan(SemanticModel semanticModel, SourceLocation position, T node)
        {
            var nameToken = GetNameToken(node);

            if (!nameToken.SourceRange.ContainsOrTouches(position))
            {
                return(null);
            }

            if (!nameToken.Span.IsInRootFile)
            {
                return(null);
            }

            var symbol = semanticModel.GetSymbol(node);

            if (symbol == null)
            {
                return(null);
            }

            var definition = semanticModel.FindUsages(symbol)
                             .FirstOrDefault(x => x.Kind == SymbolSpanKind.Definition);

            if (definition == default(SymbolSpan))
            {
                return(null);
            }

            return(definition.Span);
        }
Exemple #2
0
        public IEnumerable <HighlightSpan> GetHighlights(SemanticModel semanticModel, SourceLocation position)
        {
            var symbolAtPosition = semanticModel.FindSymbol(position);

            if (symbolAtPosition == null)
            {
                return(Enumerable.Empty <HighlightSpan>());
            }

            return(semanticModel.FindUsages(symbolAtPosition.Value.Symbol)
                   .Select(s => new HighlightSpan(s.Span, s.Kind == SymbolSpanKind.Definition)));
        }
Exemple #3
0
        public IEnumerable <TextSpan> GetHighlights(SemanticModel semanticModel, int position)
        {
            if (semanticModel == null)
            {
                throw new ArgumentNullException(nameof(semanticModel));
            }

            var symbolAtPosition = semanticModel.FindSymbol(position);

            if (symbolAtPosition == null)
            {
                return(Enumerable.Empty <TextSpan>());
            }

            return(semanticModel.FindUsages(symbolAtPosition.Value.Symbol)
                   .Select(s => s.Span));
        }