/// <summary> /// Computes a span for a given field symbol, expanding to the outer /// </summary> private static TextSpan GetVariableDeclarationSpan(SyntaxTreeBase tree, SyntaxNode node, SourceFileSpan nodeFileSpan) { int spanStart = nodeFileSpan.Span.Start; int spanEnd = nodeFileSpan.Span.End; var fieldDeclaration = node.GetAncestor <VariableDeclarationStatementSyntax>(); if (fieldDeclaration != null) { var variables = fieldDeclaration.Declaration.Variables; var fieldDeclarationFileSpan = tree.GetSourceFileSpan(fieldDeclaration.SourceRange); if (fieldDeclarationFileSpan.IsInRootFile) { if (variables.FirstOrDefault() == node) { spanStart = fieldDeclarationFileSpan.Span.Start; } if (variables.LastOrDefault() == node) { spanEnd = fieldDeclarationFileSpan.Span.End; } } } return(TextSpan.FromBounds(spanStart, spanEnd)); }
private static IList <NavigationBarItem> CreateItems(ISymbol symbol, IList <NavigationBarItem> childItems, SyntaxTreeBase tree, CancellationToken cancellationToken) { var result = new List <NavigationBarItem>(); if (symbol.Locations.Length == 0) { return(result); } var locationsLength = symbol.Kind == SymbolKind.Function ? symbol.Locations.Length : 1; for (var i = 0; i < locationsLength; i++) { if (cancellationToken.IsCancellationRequested) { return(SpecializedCollections.EmptyList <NavigationBarItem>()); } // TODO: This is a hack, it assumes too much about ISymbol's properties. var nameSourceRange = symbol.Locations[i]; var node = (SyntaxNode)symbol.DeclaringSyntaxNodes[i]; var nameFileSpan = tree.GetSourceFileSpan(nameSourceRange); if (!nameFileSpan.IsInRootFile) { continue; } var nodeFileSpan = node.GetTextSpanSafe(); if (nodeFileSpan == null || !nodeFileSpan.Value.IsInRootFile) { continue; } var nodeSpan = nodeFileSpan.Value.Span; if (symbol.Kind == SymbolKind.Field || symbol.Kind == SymbolKind.Variable) { nodeSpan = GetVariableDeclarationSpan(tree, node, nodeFileSpan.Value); } result.Add(new NavigationBarSymbolItem( symbol.ToDisplayString(SymbolDisplayFormat.NavigationBar), symbol.GetGlyph(), SpecializedCollections.SingletonList(nodeSpan), nameFileSpan.Span, childItems)); } return(result); }
private async Task <QuickInfoItem> GetQuickInfoItemAsync( Document document, SyntaxTreeBase syntaxTree, ISyntaxToken token, SourceLocation sourceLocation, CancellationToken cancellationToken) { if (token != default(ISyntaxToken) && token.SourceRange.Contains(sourceLocation)) { var deferredContent = await BuildContentAsync(document, token, cancellationToken).ConfigureAwait(false); if (deferredContent != null) { var rootSpan = syntaxTree.GetSourceFileSpan(token.SourceRange).Span; return(new QuickInfoItem(rootSpan, deferredContent)); } } return(null); }
private static IEnumerable <INavigateToSearchResult> ConvertResult( ISymbol declaredSymbol, Document document, SyntaxTreeBase syntaxTree, NavigateToMatchKind matchKind) { var isCaseSensitive = false; var kind = GetItemKind(declaredSymbol.Kind); foreach (var location in declaredSymbol.Locations) { var sourceFileSpan = syntaxTree.GetSourceFileSpan(location); if (sourceFileSpan.IsInRootFile) { var navigableItem = NavigableItemFactory.GetItemFromDeclaredSymbol( declaredSymbol, document, sourceFileSpan); yield return(new SearchResult( document, declaredSymbol, kind, matchKind, isCaseSensitive, navigableItem)); } } }
private static MappedDiagnostic MapDiagnostic(SyntaxTreeBase syntaxTree, Diagnostic diagnostic, DiagnosticSource source, LogicalDocument logicalDocument) { var fileSpan = syntaxTree.GetSourceFileSpan(diagnostic.SourceRange); return(new MappedDiagnostic(diagnostic, source, fileSpan, logicalDocument)); }