Exemplo n.º 1
0
        private IEnumerable <IPackageIndexModelInfo> CollectTypeSuggestions(SyntaxNode node, IEnumerable <TargetFrameworkMetadata> distinctTargetFrameworks)
        {
            var potentialSuggestions = new List <IPackageIndexModelInfo>();

            if (_syntaxHelper.IsType(node))
            {
                var entityNamesToSearchFor = new List <string>();
                var entityName             = node.ToString().NormalizeGenericName();
                entityNamesToSearchFor.Add(entityName);

                if (_syntaxHelper.IsAttribute(node) && !entityName.EndsWith("Attribute"))
                {
                    entityNamesToSearchFor.Add(entityName + "Attribute");
                }

                foreach (var entity in entityNamesToSearchFor)
                {
                    var suggestions = _packageSearcher.SearchType(entity);
                    if (suggestions != null)
                    {
                        potentialSuggestions.AddRange(suggestions);
                    }
                }
            }

            if (potentialSuggestions == null || !potentialSuggestions.Any())
            {
                return(Enumerable.Empty <IPackageIndexModelInfo>());
            }

            return(TargetFrameworkHelper.GetSupportedPackages(potentialSuggestions,
                                                              distinctTargetFrameworks,
                                                              allowHigherVersions: true));
        }
Exemplo n.º 2
0
        public IList <IPackageIndexModelInfo> GetSuggestions(SyntaxNode node, IEnumerable <ProjectMetadata> projects)
        {
            if (node == null || projects == null || !projects.Any())
            {
                return(null);
            }

            // get distinct frameworks from all projects current file belongs to
            var distinctTargetFrameworks = TargetFrameworkHelper.GetDistinctTargetFrameworks(projects);

            var suggestions = new List <IPackageIndexModelInfo>(CollectNamespaceSuggestions(node, distinctTargetFrameworks));

            suggestions.AddRange(CollectExtensionSuggestions(node, distinctTargetFrameworks));
            suggestions.AddRange(CollectTypeSuggestions(node, distinctTargetFrameworks));

            return(suggestions);
        }
Exemplo n.º 3
0
        private IEnumerable <IPackageIndexModelInfo> CollectNamespaceSuggestions(SyntaxNode node, IEnumerable <TargetFrameworkMetadata> distinctTargetFrameworks)
        {
            string entityName;
            IEnumerable <IPackageIndexModelInfo> potentialSuggestions = null;

            if (_syntaxHelper.IsImport(node, out entityName))
            {
                potentialSuggestions = _packageSearcher.SearchNamespace(entityName);
            }

            if (potentialSuggestions == null || !potentialSuggestions.Any())
            {
                return(Enumerable.Empty <IPackageIndexModelInfo>());
            }

            return(TargetFrameworkHelper.GetSupportedPackages(potentialSuggestions,
                                                              distinctTargetFrameworks,
                                                              allowHigherVersions: true));
        }
Exemplo n.º 4
0
        private IEnumerable <IPackageIndexModelInfo> CollectExtensionSuggestions(SyntaxNode node, IEnumerable <TargetFrameworkMetadata> distinctTargetFrameworks)
        {
            string entityName;
            IEnumerable <IPackageIndexModelInfo> potentialSuggestions = null;

            if (_syntaxHelper.IsExtension(node))
            {
                entityName = node.ToString().NormalizeGenericName();

                potentialSuggestions = _packageSearcher.SearchExtension(entityName);
            }

            if (potentialSuggestions == null || !potentialSuggestions.Any())
            {
                return(Enumerable.Empty <IPackageIndexModelInfo>());
            }

            return(TargetFrameworkHelper.GetSupportedPackages(potentialSuggestions,
                                                              distinctTargetFrameworks,
                                                              allowHigherVersions: true));
        }