private async Task <IList <SymbolReference> > GetNamespacesForMatchingNamespacesAsync(
                SearchScope searchScope)
            {
                searchScope.CancellationToken.ThrowIfCancellationRequested();

                TSimpleNameSyntax nameNode;

                if (!_owner.CanAddImportForNamespace(_diagnostic, _node, out nameNode))
                {
                    return(null);
                }

                string name;
                int    arity;

                _syntaxFacts.GetNameAndArityOfSimpleName(nameNode, out name, out arity);

                if (arity > 0)
                {
                    return(null);
                }

                if (ExpressionBinds(searchScope, nameNode, checkForExtensionMethods: false))
                {
                    return(null);
                }

                var symbols = await searchScope.FindDeclarationsAsync(name, nameNode, SymbolFilter.Namespace).ConfigureAwait(false);

                return(GetProposedNamespaces(
                           searchScope, OfType <INamespaceSymbol>(symbols).Select(s => s.WithSymbol(s.Symbol.ContainingNamespace))));
            }
            private async Task <IList <SymbolReference> > GetNamespacesForMatchingNamespacesAsync(SearchScope searchScope)
            {
                if (!_owner.CanAddImportForNamespace(_diagnostic, ref _node))
                {
                    return(null);
                }

                string name;
                int    arity;

                _syntaxFacts.GetNameAndArityOfSimpleName(_node, out name, out arity);

                if (ExpressionBinds(checkForExtensionMethods: false))
                {
                    return(null);
                }

                var symbols = await searchScope.FindDeclarationsAsync(name, SymbolFilter.Namespace).ConfigureAwait(false);

                return(GetProposedNamespaces(
                           searchScope, symbols.OfType <INamespaceSymbol>().Select(n => n.ContainingNamespace)));
            }
Esempio n. 3
0
            /// <summary>
            /// Searches for namespaces that match the name the user has written.  Returns <see cref="SymbolReference"/>s
            /// to the <see cref="INamespaceSymbol"/>s those namespaces are contained in.
            /// </summary>
            private async Task <ImmutableArray <SymbolReference> > GetReferencesForMatchingNamespacesAsync(
                SearchScope searchScope)
            {
                searchScope.CancellationToken.ThrowIfCancellationRequested();
                if (_owner.CanAddImportForNamespace(_diagnostic, _node, out var nameNode))
                {
                    _syntaxFacts.GetNameAndArityOfSimpleName(nameNode, out var name, out var arity);

                    if (arity == 0 &&
                        !ExpressionBinds(nameNode, checkForExtensionMethods: false, cancellationToken: searchScope.CancellationToken))
                    {
                        var symbols = await searchScope.FindDeclarationsAsync(name, nameNode, SymbolFilter.Namespace).ConfigureAwait(false);

                        var namespaceSymbols           = OfType <INamespaceSymbol>(symbols);
                        var containingNamespaceSymbols = OfType <INamespaceSymbol>(symbols).SelectAsArray(s => s.WithSymbol(s.Symbol.ContainingNamespace));

                        return(GetNamespaceSymbolReferences(searchScope, containingNamespaceSymbols));
                    }
                }

                return(ImmutableArray <SymbolReference> .Empty);
            }