示例#1
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));
        }
            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);
            }
示例#3
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));
        }
        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));
        }
示例#5
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);
        }
        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));
        }
 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);
 }
 private bool IsCandidateProject(AbstractSyntaxContext context, CancellationToken cancellationToken)
 {
     var syntaxFacts = context.GetLanguageService<ISyntaxFactsService>();
     return !syntaxFacts.IsInInactiveRegion(context.SyntaxTree, context.Position, cancellationToken);
 }
        private bool IsCandidateProject(AbstractSyntaxContext context, CancellationToken cancellationToken)
        {
            var syntaxFacts = context.GetLanguageService <ISyntaxFactsService>();

            return(!syntaxFacts.IsInInactiveRegion(context.SyntaxTree, context.Position, cancellationToken));
        }
示例#10
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)));
        }
 protected override Task<IEnumerable<ISymbol>> GetSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
 {
     var recommender = context.GetLanguageService<IRecommendationService>();
     return recommender.GetRecommendedSymbolsAtPositionAsync(context.Workspace, context.SemanticModel, position, options, cancellationToken);
 }
示例#12
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));
        }