private static TokenSemanticInfo GetSemanticInfo( SemanticModel semanticModel, ISemanticFactsService semanticFacts, ISyntaxFactsService syntaxFacts, SyntaxToken token, CancellationToken cancellationToken) { var aliasSymbol = semanticModel.GetAliasInfo(token.Parent, cancellationToken); var bindableParent = syntaxFacts.GetBindableParent(token); var type = semanticModel.GetTypeInfo(bindableParent, cancellationToken).Type; var declaredSymbol = MapSymbol(semanticFacts.GetDeclaredSymbol(semanticModel, token, cancellationToken), type); var allSymbols = semanticModel.GetSymbolInfo(bindableParent, cancellationToken) .GetBestOrAllSymbols() .WhereAsArray(s => !s.Equals(declaredSymbol)) .SelectAsArray(s => MapSymbol(s, type)); // NOTE(cyrusn): This is a workaround to how the semantic model binds and returns // information for VB event handlers. Namely, if you have: // // Event X]() // Sub Foo() // Dim y = New $$XEventHandler(AddressOf bar) // End Sub // // Only GetTypeInfo will return any information for XEventHandler. So, in this // case, we upgrade the type to be the symbol we return. if (type != null && allSymbols.Length == 0) { if (type.Kind == SymbolKind.NamedType) { var namedType = (INamedTypeSymbol)type; if (namedType.TypeKind == TypeKind.Delegate || namedType.AssociatedSymbol != null) { allSymbols = ImmutableArray.Create <ISymbol>(type); type = null; } } } return(new TokenSemanticInfo(declaredSymbol, aliasSymbol, allSymbols, type)); }
private static TokenSemanticInfo GetSemanticInfo( SemanticModelBase semanticModel, ISemanticFactsService semanticFacts, ISyntaxFactsService syntaxFacts, ISyntaxToken token, CancellationToken cancellationToken) { //var aliasSymbol = semanticModel.GetAliasInfo(token.Parent, cancellationToken); IAliasSymbol aliasSymbol = null; var bindableParent = syntaxFacts.GetBindableParent(token); var type = semanticModel.GetTypeInfo(bindableParent).Type; var declaredSymbol = semanticFacts.GetDeclaredSymbol(semanticModel, token, cancellationToken); var allSymbols = semanticModel.GetSymbolInfo(bindableParent) .GetBestOrAllSymbols() .WhereAsArray(s => !s.Equals(declaredSymbol)) .SelectAsArray(s => s); return(new TokenSemanticInfo(declaredSymbol, aliasSymbol, allSymbols, type)); }
private static Func <SyntaxToken, SyntaxNode> GetFindParentNodeFunction(ISyntaxFactsService syntaxFacts) { return(t => syntaxFacts.GetBindableParent(t)); }
private static IEnumerable <ISymbol> GetSymbolsEnumerable( SemanticModel semanticModel, ISemanticFactsService semanticFacts, ISyntaxFactsService syntaxFacts, SyntaxToken token, bool bindLiteralsToUnderlyingType, CancellationToken cancellationToken) { var declaredSymbol = semanticFacts.GetDeclaredSymbol(semanticModel, token, cancellationToken); if (declaredSymbol != null) { yield return(declaredSymbol); yield break; } var aliasInfo = semanticModel.GetAliasInfo(token.Parent, cancellationToken); if (aliasInfo != null) { yield return(aliasInfo); } var bindableParent = syntaxFacts.GetBindableParent(token); var allSymbols = semanticModel.GetSymbolInfo(bindableParent, cancellationToken).GetBestOrAllSymbols().ToList(); var type = semanticModel.GetTypeInfo(bindableParent, cancellationToken).Type; if (type != null && allSymbols.Count == 0) { if ((bindLiteralsToUnderlyingType && syntaxFacts.IsLiteral(token)) || syntaxFacts.IsAwaitKeyword(token)) { yield return(type); } if (type.Kind == SymbolKind.NamedType) { var namedType = (INamedTypeSymbol)type; if (namedType.TypeKind == TypeKind.Delegate || namedType.AssociatedSymbol != null) { yield return(type); } } } foreach (var symbol in allSymbols) { if (symbol.IsThisParameter() && type != null) { yield return(type); } else if (symbol.IsFunctionValue()) { var method = symbol.ContainingSymbol as IMethodSymbol; if (method != null) { if (method.AssociatedSymbol != null) { yield return(method.AssociatedSymbol); } else { yield return(method); } } else { yield return(symbol); } } else { yield return(symbol); } } }