コード例 #1
0
ファイル: SymbolCompletionItem.cs プロジェクト: Eyas/roslyn
 public SymbolCompletionItem(
     CompletionListProvider completionProvider,
     string displayText,
     string insertionText,
     string filterText,
     TextSpan filterSpan,
     int position,
     List<ISymbol> symbols,
     string sortText,
     AbstractSyntaxContext context,
     Glyph glyph,
     bool preselect = false,
     SupportedPlatformData supportedPlatforms = null,
     CompletionItemRules rules = null)
 : base(completionProvider, displayText, filterSpan,
    descriptionFactory: null, glyph: glyph,
    sortText: sortText, filterText: filterText, preselect: preselect, showsWarningIcon: supportedPlatforms != null, rules: rules,
    filters: GetFilters(symbols))
 {
     this.InsertionText = insertionText;
     this.Position = position;
     this.Symbols = symbols;
     this.Context = context;
     _supportedPlatforms = supportedPlatforms;
 }
コード例 #2
0
        protected override ValueTuple<string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context)
        {
            var insertionText = ItemRules.GetInsertionText(symbol, context);
            var displayText = symbol.GetArity() == 0 ? insertionText : string.Format("{0}<>", insertionText);

            return ValueTuple.Create(displayText, insertionText);
        }
コード例 #3
0
 public SymbolCompletionItem(
     CompletionListProvider completionProvider,
     string displayText,
     string insertionText,
     string filterText,
     TextSpan filterSpan,
     int position,
     List <ISymbol> symbols,
     string sortText,
     AbstractSyntaxContext context,
     Glyph glyph,
     bool preselect = false,
     SupportedPlatformData supportedPlatforms = null,
     CompletionItemRules rules = null)
     : base(completionProvider, displayText, filterSpan,
            descriptionFactory : null, glyph : glyph,
            sortText : sortText, filterText : filterText, preselect : preselect, showsWarningIcon : supportedPlatforms != null, rules : rules,
            filters : GetFilters(symbols))
 {
     this.InsertionText  = insertionText;
     this.Position       = position;
     this.Symbols        = symbols;
     this.Context        = context;
     _supportedPlatforms = supportedPlatforms;
 }
コード例 #4
0
        /// <summary>
        /// Given a Symbol, creates the completion item for it.
        /// </summary>
        private CompletionItem CreateItem(
            ValueTuple <string, string> displayAndInsertionText,
            int position,
            List <ISymbol> symbols,
            AbstractSyntaxContext context,
            TextSpan textChangeSpan,
            Dictionary <ISymbol, List <ProjectId> > invalidProjectMap,
            List <ProjectId> totalProjects,
            bool preselect,
            CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(symbols);

            SupportedPlatformData supportedPlatformData = null;

            if (invalidProjectMap != null)
            {
                List <ProjectId> invalidProjects = null;
                foreach (var symbol in symbols)
                {
                    if (invalidProjectMap.TryGetValue(symbol, out invalidProjects))
                    {
                        break;
                    }
                }

                if (invalidProjects != null)
                {
                    supportedPlatformData = new SupportedPlatformData(invalidProjects, totalProjects, context.Workspace);
                }
            }

            return(CreateItem(displayAndInsertionText, position, symbols, context, textChangeSpan, preselect, supportedPlatformData));
        }
コード例 #5
0
        /// <summary>
        /// Given a Symbol, creates the completion item for it.
        /// </summary>
        private CompletionItem CreateItem(
            string displayText, 
            string insertionText,
            int position,
            List<ISymbol> symbols,
            AbstractSyntaxContext context,
            Dictionary<ISymbol, List<ProjectId>> invalidProjectMap,
            List<ProjectId> totalProjects,
            bool preselect)
        {
            Contract.ThrowIfNull(symbols);

            SupportedPlatformData supportedPlatformData = null;
            if (invalidProjectMap != null)
            {
                List<ProjectId> invalidProjects = null;
                foreach (var symbol in symbols)
                {
                    if (invalidProjectMap.TryGetValue(symbol, out invalidProjects))
                    {
                        break;
                    }
                }

                if (invalidProjects != null)
                {
                    supportedPlatformData = new SupportedPlatformData(invalidProjects, totalProjects, context.Workspace);
                }
            }

            return CreateItem(displayText, insertionText, position, symbols, context, preselect, supportedPlatformData);
        }
コード例 #6
0
 protected virtual string GetFilterText(ISymbol symbol, string displayText, AbstractSyntaxContext context)
 {
     return((displayText == symbol.Name) ||
            (displayText.Length > 0 && displayText[0] == '@') ||
            (context.IsAttributeNameContext && symbol.IsAttribute())
         ? displayText
         : symbol.Name);
 }
コード例 #7
0
        protected override IEnumerable<INamedTypeSymbol> LookupCandidateSymbols(AbstractSyntaxContext context, INamedTypeSymbol declaredSymbol, CancellationToken cancellationToken)
        {
            var candidates = base.LookupCandidateSymbols(context, declaredSymbol, cancellationToken);

            // The base class applies a broad filter when finding candidates, but since C# requires
            // that all parts have the "partial" modifier, the results can be trimmed further here.
            return candidates?.Where(symbol => symbol.DeclaringSyntaxReferences.Any(reference => IsPartialTypeDeclaration(reference.GetSyntax(cancellationToken))));
        }
コード例 #8
0
        protected override ValueTuple<string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context)
        {
            if (symbol is IAliasSymbol)
            {
                return ValueTuple.Create(symbol.Name, symbol.Name);
            }

            return base.GetDisplayAndInsertionText(symbol, context);
        }
コード例 #9
0
            protected override string GetInsertionText(ISymbol symbol, AbstractSyntaxContext context, char ch)
            {
                if (symbol is IAliasSymbol)
                {
                    return ((IAliasSymbol)symbol).Name;
                }

                var displayService = context.GetLanguageService<ISymbolDisplayService>();
                return displayService.ToMinimalDisplayString(context.SemanticModel, context.Position, symbol);
            }
コード例 #10
0
        protected override string GetInsertionText(ISymbol symbol, AbstractSyntaxContext context, char ch)
        {
            if (symbol is IAliasSymbol)
            {
                return(((IAliasSymbol)symbol).Name);
            }

            var displayService = context.GetLanguageService <ISymbolDisplayService>();

            return(displayService.ToMinimalDisplayString(context.SemanticModel, context.Position, symbol));
        }
コード例 #11
0
        private CompletionItem CreateCompletionItem(INamedTypeSymbol symbol, TextSpan textSpan, int position, AbstractSyntaxContext context)
        {
            var displayAndInsertionText = GetDisplayAndInsertionText(symbol, context);

            return SymbolCompletionItem.Create(
                displayText: displayAndInsertionText.Item1,
                insertionText: displayAndInsertionText.Item2,
                symbol: symbol,
                contextPosition: context.Position,
                descriptionPosition: position,
                rules: CompletionItemRules.Default);
        }
コード例 #12
0
        protected override async Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
        {
            var result = await base.GetPreselectedSymbolsWorker(context, position, options, cancellationToken).ConfigureAwait(false);
            if (result.Any())
            {
                var type = (ITypeSymbol)result.Single();
                var alias = await type.FindApplicableAlias(position, context.SemanticModel, cancellationToken).ConfigureAwait(false);
                if (alias != null)
                {
                    return SpecializedCollections.SingletonEnumerable(alias);
                }
            }

            return result;
        }
コード例 #13
0
 protected override CompletionItem CreateItem(string displayText, string insertionText, int position, List<ISymbol> symbols, AbstractSyntaxContext context, TextSpan span, bool preselect, SupportedPlatformData supportedPlatformData)
 {
     return SymbolCompletionItem.Create(
         displayText: displayText,
         insertionText: insertionText,
         filterText: GetFilterText(symbols[0], displayText, context),
         span: span,
         contextPosition: context.Position,
         descriptionPosition: position,
         symbols: symbols,
         supportedPlatforms: supportedPlatformData,
         preselect: preselect,
         tags: s_Tags,
         rules: GetCompletionItemRules(symbols, context));
 }
コード例 #14
0
        public static string GetInsertionText(ISymbol symbol, AbstractSyntaxContext context)
        {
            string name;

            if (CommonCompletionUtilities.TryRemoveAttributeSuffix(symbol, context.IsAttributeNameContext, context.GetLanguageService<ISyntaxFactsService>(), out name))
            {
                // Cannot escape Attribute name with the suffix removed. Only use the name with
                // the suffix removed if it does not need to be escaped.
                if (name.Equals(name.EscapeIdentifier()))
                {
                    return name;
                }
            }

            return symbol.Name.EscapeIdentifier(isQueryContext: context.IsInQuery);
        }
コード例 #15
0
        public static string GetInsertionText(ISymbol symbol, AbstractSyntaxContext context)
        {
            string name;

            if (CommonCompletionUtilities.TryRemoveAttributeSuffix(symbol, context.IsAttributeNameContext, context.GetLanguageService <ISyntaxFactsService>(), out name))
            {
                // Cannot escape Attribute name with the suffix removed. Only use the name with
                // the suffix removed if it does not need to be escaped.
                if (name.Equals(name.EscapeIdentifier()))
                {
                    return(name);
                }
            }

            return(symbol.Name.EscapeIdentifier(isQueryContext: context.IsInQuery));
        }
コード例 #16
0
        /// <summary>
        /// Given a list of symbols, creates the list of completion items for them.
        /// </summary>
        protected IEnumerable<CompletionItem> CreateItems(
            int position,
            IEnumerable<ISymbol> symbols,
            AbstractSyntaxContext context,
            Dictionary<ISymbol, List<ProjectId>> invalidProjectMap,
            List<ProjectId> totalProjects,
            bool preselect)
        {
            var tree = context.SyntaxTree;

            var q = from symbol in symbols
                    let texts = GetDisplayAndInsertionText(symbol, context)
                    group symbol by texts into g
                    select this.CreateItem(g.Key.Item1, g.Key.Item2, position, g.ToList(), context, invalidProjectMap, totalProjects, preselect);

            return q.ToList();
        }
コード例 #17
0
 public SymbolCompletionItem(
     CompletionListProvider completionProvider,
     string displayText,
     string insertionText,
     string filterText,
     TextSpan filterSpan,
     int position,
     List <ISymbol> symbols,
     AbstractSyntaxContext context,
     bool preselect = false,
     SupportedPlatformData supportedPlatforms = null,
     CompletionItemRules rules = null)
     : this(completionProvider, displayText, insertionText, filterText, filterSpan, position,
            symbols, sortText : symbols[0].Name, context : context, glyph : symbols[0].GetGlyph(),
            preselect : preselect, supportedPlatforms : supportedPlatforms, rules : rules)
 {
 }
コード例 #18
0
ファイル: SymbolCompletionItem.cs プロジェクト: Eyas/roslyn
 public SymbolCompletionItem(
     CompletionListProvider completionProvider,
     string displayText,
     string insertionText,
     string filterText,
     TextSpan filterSpan,
     int position,
     List<ISymbol> symbols,
     AbstractSyntaxContext context,
     bool preselect = false,
     SupportedPlatformData supportedPlatforms = null,
     CompletionItemRules rules = null)
 : this(completionProvider, displayText, insertionText, filterText, filterSpan, position,
       symbols, sortText: symbols[0].Name, context: context, glyph: symbols[0].GetGlyph(),
       preselect: preselect, supportedPlatforms: supportedPlatforms, rules: rules)
 {
 }
コード例 #19
0
        /// <summary>
        /// Given a list of symbols, creates the list of completion items for them.
        /// </summary>
        protected IEnumerable <CompletionItem> CreateItems(
            int position,
            IEnumerable <ISymbol> symbols,
            TextSpan span,
            AbstractSyntaxContext context,
            Dictionary <ISymbol, List <ProjectId> > invalidProjectMap,
            List <ProjectId> totalProjects,
            bool preselect)
        {
            var tree = context.SyntaxTree;

            var q = from symbol in symbols
                    let texts = GetDisplayAndInsertionText(symbol, context)
                                group symbol by texts into g
                                select this.CreateItem(g.Key.Item1, g.Key.Item2, position, g.ToList(), context, span, invalidProjectMap, totalProjects, preselect);

            return(q.ToList());
        }
コード例 #20
0
 public SymbolCompletionItem(
     ICompletionProvider completionProvider,
     string displayText,
     string insertionText,
     TextSpan filterSpan,
     int position,
     List <ISymbol> symbols,
     AbstractSyntaxContext context,
     bool preselect = false,
     SupportedPlatformData supportedPlatforms = null)
     : this(completionProvider,
            displayText,
            insertionText,
            filterText : displayText.Length > 0 && displayText[0] == '@' ? displayText : symbols[0].Name,
            filterSpan : filterSpan,
            position : position, symbols : symbols, context : context, preselect : preselect, supportedPlatforms : supportedPlatforms)
 {
 }
コード例 #21
0
 public SymbolCompletionItem(
     CompletionListProvider completionProvider,
     string displayText,
     string insertionText,
     TextSpan filterSpan,
     int position,
     List<ISymbol> symbols,
     AbstractSyntaxContext context,
     bool preselect = false,
     SupportedPlatformData supportedPlatforms = null)
     : this(completionProvider,
           displayText,
           insertionText,
           filterText: displayText.Length > 0 && displayText[0] == '@' ? displayText : symbols[0].Name,
           filterSpan: filterSpan,
           position: position, symbols: symbols, context: context, preselect: preselect, supportedPlatforms: supportedPlatforms)
 {
 }
コード例 #22
0
        /// <summary>
        /// Given a list of symbols, creates the list of completion items for them.
        /// </summary>
        protected async Task<IEnumerable<CompletionItem>> CreateItemsAsync(
            int position,
            IEnumerable<ISymbol> symbols,
            AbstractSyntaxContext context,
            Dictionary<ISymbol, List<ProjectId>> invalidProjectMap,
            List<ProjectId> totalProjects,
            bool preselect,
            CancellationToken cancellationToken)
        {
            var tree = context.SyntaxTree;

            var text = await context.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);
            var textChangeSpan = this.GetTextChangeSpan(text, position);
            var q = from symbol in symbols
                    let texts = GetDisplayAndInsertionText(symbol, context)
                    group symbol by texts into g
                    select this.CreateItem(g.Key, position, g.ToList(), context, textChangeSpan, invalidProjectMap, totalProjects, preselect, cancellationToken);

            return q.ToList();
        }
        protected override CompletionItem CreateItem(string displayText, string insertionText, int position, List<ISymbol> symbols, AbstractSyntaxContext context, bool preselect, SupportedPlatformData supportedPlatformData)
        {
            var matchPriority = preselect ? ComputeSymbolMatchPriority(symbols[0]) : MatchPriority.Default;
            var rules = GetCompletionItemRules(symbols, context, preselect);
            if (preselect)
            {
                rules = rules.WithSelectionBehavior(PreselectedItemSelectionBehavior);
            }

            return SymbolCompletionItem.Create(
                displayText: displayText,
                insertionText: insertionText,
                filterText: GetFilterText(symbols[0], displayText, context),
                contextPosition: context.Position,
                descriptionPosition: position,
                symbols: symbols,
                supportedPlatforms: supportedPlatformData,
                matchPriority: matchPriority,
                rules: rules);
        }
コード例 #24
0
        /// <summary>
        /// Given a list of symbols, creates the list of completion items for them.
        /// </summary>
        protected async Task <IEnumerable <CompletionItem> > CreateItemsAsync(
            int position,
            IEnumerable <ISymbol> symbols,
            AbstractSyntaxContext context,
            Dictionary <ISymbol, List <ProjectId> > invalidProjectMap,
            List <ProjectId> totalProjects,
            bool preselect,
            CancellationToken cancellationToken)
        {
            var tree = context.SyntaxTree;

            var text = await context.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);

            var textChangeSpan = this.GetTextChangeSpan(text, position);
            var q = from symbol in symbols
                    let texts = GetDisplayAndInsertionText(symbol, context)
                                group symbol by texts into g
                                select this.CreateItem(g.Key, position, g.ToList(), context, textChangeSpan, invalidProjectMap, totalProjects, preselect, cancellationToken);

            return(q.ToList());
        }
コード例 #25
0
 public SymbolCompletionItem(
     ICompletionProvider completionProvider,
     string displayText,
     string insertionText,
     string filterText,
     TextSpan filterSpan,
     int position,
     List<ISymbol> symbols,
     AbstractSyntaxContext context,
     bool preselect = false,
     SupportedPlatformData supportedPlatforms = null)
 : base(completionProvider, displayText, filterSpan,
    descriptionFactory: null, glyph: symbols[0].GetGlyph(),
    sortText: symbols[0].Name, filterText: filterText, preselect: preselect, showsWarningIcon: supportedPlatforms != null)
 {
     this.InsertionText = insertionText;
     this.Position = position;
     this.Symbols = symbols;
     this.Context = context;
     _supportedPlatorms = supportedPlatforms;
 }
コード例 #26
0
 public SymbolCompletionItem(
     ICompletionProvider completionProvider,
     string displayText,
     string insertionText,
     string filterText,
     TextSpan filterSpan,
     int position,
     List <ISymbol> symbols,
     AbstractSyntaxContext context,
     bool preselect = false,
     SupportedPlatformData supportedPlatforms = null)
     : base(completionProvider, displayText, filterSpan,
            descriptionFactory : null, glyph : symbols[0].GetGlyph(),
            sortText : symbols[0].Name, filterText : filterText, preselect : preselect, showsWarningIcon : supportedPlatforms != null)
 {
     this.InsertionText     = insertionText;
     this.Position          = position;
     this.Symbols           = symbols;
     this.Context           = context;
     this.supportedPlatorms = supportedPlatforms;
 }
コード例 #27
0
        protected virtual IEnumerable<INamedTypeSymbol> LookupCandidateSymbols(AbstractSyntaxContext context, INamedTypeSymbol declaredSymbol, CancellationToken cancellationToken)
        {
            if (declaredSymbol == null)
            {
                throw new ArgumentNullException(nameof(declaredSymbol));
            }

            SemanticModel semanticModel = context.SemanticModel;

            INamespaceOrTypeSymbol containingSymbol = declaredSymbol.ContainingSymbol as INamespaceOrTypeSymbol;

            if (containingSymbol == null)
            {
                return SpecializedCollections.EmptyEnumerable<INamedTypeSymbol>();
            }

            return semanticModel.LookupNamespacesAndTypes(context.Position, containingSymbol)
                                .OfType<INamedTypeSymbol>()
                                .Where(symbol => declaredSymbol.TypeKind == symbol.TypeKind &&
                                                 NotNewDeclaredMember(symbol, context) &&
                                                 InSameProject(symbol, semanticModel.Compilation));
        }
        protected override async Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
        {
            var recommender = context.GetLanguageService<IRecommendationService>();
            var typeInferrer = context.GetLanguageService<ITypeInferenceService>();

            var inferredTypes = typeInferrer.InferTypes(context.SemanticModel, position, cancellationToken)
                .Where(t => t.SpecialType != SpecialType.System_Void)
                .ToSet();
            if (inferredTypes.Count == 0)
            {
                return SpecializedCollections.EmptyEnumerable<ISymbol>();
            }

            var symbols = await recommender.GetRecommendedSymbolsAtPositionAsync(
                context.Workspace, 
                context.SemanticModel, 
                position, 
                options, 
                cancellationToken).ConfigureAwait(false);

            // Don't preselect intrinsic type symbols so we can preselect their keywords instead.
            return symbols.Where(s => inferredTypes.Contains(GetSymbolType(s)) && !IsInstrinsic(s));
        }
コード例 #29
0
 protected abstract string GetInsertionText(ISymbol symbol, AbstractSyntaxContext context, char ch);
 protected override Task<IEnumerable<ISymbol>> GetSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
 {
     return SpecializedTasks.EmptyEnumerable<ISymbol>();
 }
コード例 #31
0
 protected abstract ValueTuple <string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context);
コード例 #32
0
 private Task<IEnumerable<ISymbol>> GetSymbolsWorker(int position, bool preselect, AbstractSyntaxContext context, OptionSet options, CancellationToken cancellationToken)
 {
     return preselect
         ? GetPreselectedSymbolsWorker(context, position, options, cancellationToken)
         : GetSymbolsWorker(context, position, options, cancellationToken);
 }
コード例 #33
0
 protected OptionSet GetOptions(Document document, CompletionTriggerInfo triggerInfo, AbstractSyntaxContext context)
 {
     var optionService = context.GetWorkspaceService<IOptionService>();
     var filterOutOfScopeLocals = !triggerInfo.IsDebugger;
     var hideAdvancedMembers = document.ShouldHideAdvancedMembers();
     var options = optionService
         .GetOptions()
         .WithChangedOption(RecommendationOptions.FilterOutOfScopeLocals, context.SemanticModel.Language, filterOutOfScopeLocals)
         .WithChangedOption(RecommendationOptions.HideAdvancedMembers, context.SemanticModel.Language, hideAdvancedMembers);
     return options;
 }
コード例 #34
0
 protected virtual CompletionItem CreateItem(ValueTuple<string, string> displayAndInsertionText, int position, List<ISymbol> symbols, AbstractSyntaxContext context, TextSpan textChangeSpan, bool preselect, SupportedPlatformData supportedPlatformData)
 {
     return new SymbolCompletionItem(
         this,
         displayAndInsertionText.Item1,
         displayAndInsertionText.Item2,
         GetFilterText(symbols[0], displayAndInsertionText.Item1, context),
         textChangeSpan,
         position,
         symbols,
         context,
         supportedPlatforms: supportedPlatformData,
         preselect: preselect);
 }
コード例 #35
0
 protected abstract Task<IEnumerable<ISymbol>> GetSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken);
コード例 #36
0
 protected override Task <IEnumerable <ISymbol> > GetSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
 {
     return(Task.FromResult(Recommender.GetRecommendedSymbolsAtPosition(context.SemanticModel, position, context.Workspace, options, cancellationToken)));
 }
コード例 #37
0
 protected abstract Task <IEnumerable <ISymbol> > GetSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken);
コード例 #38
0
 internal ShouldIncludeSymbolContext(AbstractSyntaxContext context, CancellationToken cancellationToken)
 {
     _context           = context;
     _cancellationToken = cancellationToken;
 }
コード例 #39
0
 protected virtual CompletionItem CreateItem(ValueTuple <string, string> displayAndInsertionText, int position, List <ISymbol> symbols, AbstractSyntaxContext context, TextSpan textChangeSpan, bool preselect, SupportedPlatformData supportedPlatformData)
 {
     return(new SymbolCompletionItem(
                this,
                displayAndInsertionText.Item1,
                displayAndInsertionText.Item2,
                GetFilterText(symbols[0], displayAndInsertionText.Item1, context),
                textChangeSpan,
                position,
                symbols,
                context,
                supportedPlatforms: supportedPlatformData,
                preselect: preselect));
 }
コード例 #40
0
        protected override Task <IEnumerable <ISymbol> > GetPreselectedSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
        {
            var newExpression = this.GetObjectCreationNewExpression(context.SyntaxTree, position, cancellationToken);

            if (newExpression == null)
            {
                return(SpecializedTasks.EmptyEnumerable <ISymbol>());
            }

            var typeInferenceService = context.GetLanguageService <ITypeInferenceService>();
            var type = typeInferenceService.InferType(
                context.SemanticModel, position, objectAsDefault: false, cancellationToken: cancellationToken);

            // Unwrap an array type fully.  We only want to offer the underlying element type in the
            // list of completion items.
            bool isArray = false;

            while (type is IArrayTypeSymbol)
            {
                isArray = true;
                type    = ((IArrayTypeSymbol)type).ElementType;
            }

            if (type == null)
            {
                return(SpecializedTasks.EmptyEnumerable <ISymbol>());
            }

            // Unwrap nullable
            if (type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T)
            {
                type = type.GetTypeArguments().FirstOrDefault();
            }

            if (type.SpecialType == SpecialType.System_Void)
            {
                return(SpecializedTasks.EmptyEnumerable <ISymbol>());
            }

            if (type.ContainsAnonymousType())
            {
                return(SpecializedTasks.EmptyEnumerable <ISymbol>());
            }

            if (!type.CanBeReferencedByName)
            {
                return(SpecializedTasks.EmptyEnumerable <ISymbol>());
            }

            // Normally the user can't say things like "new IList".  Except for "IList[] x = new |".
            // In this case we do want to allow them to preselect certain types in the completion
            // list even if they can't new them directly.
            if (!isArray)
            {
                if (type.TypeKind == TypeKind.Interface ||
                    type.TypeKind == TypeKind.Pointer ||
                    type.TypeKind == TypeKind.Dynamic ||
                    type.IsAbstract)
                {
                    return(SpecializedTasks.EmptyEnumerable <ISymbol>());
                }

                if (type.TypeKind == TypeKind.TypeParameter &&
                    !((ITypeParameterSymbol)type).HasConstructorConstraint)
                {
                    return(SpecializedTasks.EmptyEnumerable <ISymbol>());
                }
            }

            if (!type.IsEditorBrowsable(options.GetOption(RecommendationOptions.HideAdvancedMembers, context.SemanticModel.Language), context.SemanticModel.Compilation))
            {
                return(SpecializedTasks.EmptyEnumerable <ISymbol>());
            }

            return(Task.FromResult(SpecializedCollections.SingletonEnumerable((ISymbol)type)));
        }
コード例 #41
0
 protected override CompletionItem CreateItem(string displayText, string insertionText, int position, List <ISymbol> symbols, AbstractSyntaxContext context, TextSpan span, bool preselect, SupportedPlatformData supportedPlatformData)
 {
     return(SymbolCompletionItem.Create(
                displayText: displayText,
                insertionText: insertionText,
                filterText: GetFilterText(symbols[0], displayText, context),
                span: span,
                contextPosition: context.Position,
                descriptionPosition: position,
                symbols: symbols,
                supportedPlatforms: supportedPlatformData,
                matchPriority: MatchPriority.Preselect, // Always preselect
                tags: s_Tags,
                rules: GetCompletionItemRules(symbols, context)));
 }
コード例 #42
0
        protected override async Task <IEnumerable <ISymbol> > GetPreselectedSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
        {
            var result = await base.GetPreselectedSymbolsWorker(context, position, options, cancellationToken).ConfigureAwait(false);

            if (result.Any())
            {
                var type  = (ITypeSymbol)result.Single();
                var alias = await type.FindApplicableAlias(position, context.SemanticModel, cancellationToken).ConfigureAwait(false);

                if (alias != null)
                {
                    return(SpecializedCollections.SingletonEnumerable(alias));
                }
            }

            return(result);
        }
コード例 #43
0
        protected override ValueTuple <string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context)
        {
            if (symbol is IAliasSymbol)
            {
                return(ValueTuple.Create(symbol.Name, symbol.Name));
            }

            return(base.GetDisplayAndInsertionText(symbol, context));
        }
コード例 #44
0
        private bool ShouldIncludeSymbol(ISymbol symbol, AbstractSyntaxContext context, CancellationToken cancellationToken)
        {
            var isMember = false;

            switch (symbol.Kind)
            {
            case SymbolKind.NamedType:
                var namedType = (INamedTypeSymbol)symbol;
                if (namedType.SpecialType == SpecialType.System_Void)
                {
                    return(false);
                }

                break;

            case SymbolKind.Method:
                var methodSymbol = (IMethodSymbol)symbol;
                if (methodSymbol.MethodKind == MethodKind.EventAdd ||
                    methodSymbol.MethodKind == MethodKind.EventRemove ||
                    methodSymbol.MethodKind == MethodKind.EventRaise ||
                    methodSymbol.MethodKind == MethodKind.PropertyGet ||
                    methodSymbol.MethodKind == MethodKind.PropertySet)
                {
                    return(false);
                }

                isMember = true;
                break;

            case SymbolKind.Event:
            case SymbolKind.Field:
            case SymbolKind.Property:
                isMember = true;
                break;
            }

            if (context.IsAttributeNameContext)
            {
                return(symbol.IsOrContainsAccessibleAttribute(context.SemanticModel.Compilation));
            }

            if (context.IsEnumTypeMemberAccessContext)
            {
                return(symbol.Kind == SymbolKind.Field);
            }

            // In an expression or statement context, we don't want to display instance members declared in outer containing types.
            if ((context.IsStatementContext || context.IsAnyExpressionContext) &&
                !symbol.IsStatic &&
                isMember &&
                context.GetOuterTypes(cancellationToken).Contains(symbol.ContainingType))
            {
                return(false);
            }

            var namespaceSymbol = symbol as INamespaceSymbol;

            if (namespaceSymbol != null)
            {
                return(namespaceSymbol.ContainsAccessibleTypesOrNamespaces(context.SemanticModel.Compilation.Assembly));
            }

            return(true);
        }
コード例 #45
0
 protected abstract CompletionItemRules GetCompletionItemRules(IReadOnlyList <ISymbol> symbols, AbstractSyntaxContext context);
コード例 #46
0
 protected abstract string GetInsertionText(ISymbol symbol, AbstractSyntaxContext context, char ch);
コード例 #47
0
 protected virtual string GetFilterText(ISymbol symbol, string displayText, AbstractSyntaxContext context)
 {
     return (displayText == symbol.Name) ||
         (displayText.Length > 0 && displayText[0] == '@') ||
         (context.IsAttributeNameContext && symbol.IsAttribute())
         ? displayText
         : symbol.Name;
 }
コード例 #48
0
 protected virtual CompletionItem CreateItem(string displayText, string insertionText, int position, List <ISymbol> symbols, AbstractSyntaxContext context, TextSpan span, bool preselect, SupportedPlatformData supportedPlatformData)
 {
     return(SymbolCompletionItem.Create(
                displayText: displayText,
                insertionText: insertionText,
                filterText: GetFilterText(symbols[0], displayText, context),
                span: span,
                contextPosition: context.Position,
                descriptionPosition: position,
                symbols: symbols,
                supportedPlatforms: supportedPlatformData,
                preselect: preselect,
                rules: GetCompletionItemRules(symbols, context)));
 }
コード例 #49
0
 private async Task<TextSpan> GetTextChangeSpanAsync(int position, AbstractSyntaxContext context, CancellationToken cancellationToken)
 {
     var text = await context.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);
     return GetTextChangeSpan(text, position);
 }
コード例 #50
0
        private bool IsCandidateProject(AbstractSyntaxContext context, CancellationToken cancellationToken)
        {
            var syntaxFacts = context.GetLanguageService <ISyntaxFactsService>();

            return(!syntaxFacts.IsInInactiveRegion(context.SyntaxTree, context.Position, cancellationToken));
        }
コード例 #51
0
 private bool IsCandidateProject(AbstractSyntaxContext context, CancellationToken cancellationToken)
 {
     var syntaxFacts = context.GetLanguageService<ISyntaxFactsService>();
     return !syntaxFacts.IsInInactiveRegion(context.SyntaxTree, context.Position, cancellationToken);
 }
コード例 #52
0
        protected OptionSet GetOptions(Document document, CompletionTriggerInfo triggerInfo, AbstractSyntaxContext context)
        {
            var optionService          = context.GetWorkspaceService <IOptionService>();
            var filterOutOfScopeLocals = !triggerInfo.IsDebugger;
            var hideAdvancedMembers    = document.ShouldHideAdvancedMembers();
            var options = optionService
                          .GetOptions()
                          .WithChangedOption(RecommendationOptions.FilterOutOfScopeLocals, context.SemanticModel.Language, filterOutOfScopeLocals)
                          .WithChangedOption(RecommendationOptions.HideAdvancedMembers, context.SemanticModel.Language, hideAdvancedMembers);

            return(options);
        }
コード例 #53
0
 protected abstract ValueTuple<string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context);
コード例 #54
0
        protected override ValueTuple <string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context)
        {
            var insertionText = ItemRules.GetInsertionText(symbol, context);
            var displayText   = symbol.GetArity() == 0 ? insertionText : string.Format("{0}<>", insertionText);

            return(ValueTuple.Create(displayText, insertionText));
        }
コード例 #55
0
 protected virtual Task <IEnumerable <ISymbol> > GetPreselectedSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
 {
     return(SpecializedTasks.EmptyEnumerable <ISymbol>());
 }
コード例 #56
0
 private Task <IEnumerable <ISymbol> > GetSymbolsWorker(int position, bool preselect, AbstractSyntaxContext context, OptionSet options, CancellationToken cancellationToken)
 {
     return(preselect
         ? GetPreselectedSymbolsWorker(context, position, options, cancellationToken)
         : GetSymbolsWorker(context, position, options, cancellationToken));
 }
 protected override ValueTuple<string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context)
 {
     var displayService = context.GetLanguageService<ISymbolDisplayService>();
     var displayString = displayService.ToMinimalDisplayString(context.SemanticModel, context.Position, symbol);
     return ValueTuple.Create(displayString, displayString);
 }
コード例 #58
0
        private async Task <TextSpan> GetTextChangeSpanAsync(int position, AbstractSyntaxContext context, CancellationToken cancellationToken)
        {
            var text = await context.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);

            return(GetTextChangeSpan(text, position));
        }
        protected override Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
        {
            var newExpression = this.GetObjectCreationNewExpression(context.SyntaxTree, position, cancellationToken);
            if (newExpression == null)
            {
                return SpecializedTasks.EmptyEnumerable<ISymbol>();
            }

            var typeInferenceService = context.GetLanguageService<ITypeInferenceService>();
            var type = typeInferenceService.InferType(
                context.SemanticModel, position, objectAsDefault: false, cancellationToken: cancellationToken);

            // Unwrap an array type fully.  We only want to offer the underlying element type in the
            // list of completion items.
            bool isArray = false;
            while (type is IArrayTypeSymbol)
            {
                isArray = true;
                type = ((IArrayTypeSymbol)type).ElementType;
            }

            if (type == null)
            {
                return SpecializedTasks.EmptyEnumerable<ISymbol>();
            }

            // Unwrap nullable
            if (type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T)
            {
                type = type.GetTypeArguments().FirstOrDefault();
            }

            if (type.SpecialType == SpecialType.System_Void)
            {
                return SpecializedTasks.EmptyEnumerable<ISymbol>();
            }

            if (type.ContainsAnonymousType())
            {
                return SpecializedTasks.EmptyEnumerable<ISymbol>();
            }

            if (!type.CanBeReferencedByName)
            {
                return SpecializedTasks.EmptyEnumerable<ISymbol>();
            }

            // Normally the user can't say things like "new IList".  Except for "IList[] x = new |".
            // In this case we do want to allow them to preselect certain types in the completion
            // list even if they can't new them directly.
            if (!isArray)
            {
                if (type.TypeKind == TypeKind.Interface ||
                    type.TypeKind == TypeKind.Pointer ||
                    type.TypeKind == TypeKind.Dynamic ||
                    type.IsAbstract)
                {
                    return SpecializedTasks.EmptyEnumerable<ISymbol>();
                }

                if (type.TypeKind == TypeKind.TypeParameter &&
                    !((ITypeParameterSymbol)type).HasConstructorConstraint)
                {
                    return SpecializedTasks.EmptyEnumerable<ISymbol>();
                }
            }

            if (!type.IsEditorBrowsable(options.GetOption(RecommendationOptions.HideAdvancedMembers, context.SemanticModel.Language), context.SemanticModel.Compilation))
            {
                return SpecializedTasks.EmptyEnumerable<ISymbol>();
            }

            return Task.FromResult(SpecializedCollections.SingletonEnumerable((ISymbol)type));
        }
コード例 #60
0
        protected override ValueTuple <string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context)
        {
            var displayService = context.GetLanguageService <ISymbolDisplayService>();
            var displayString  = displayService.ToMinimalDisplayString(context.SemanticModel, context.Position, symbol);

            return(ValueTuple.Create(displayString, displayString));
        }