Exemplo n.º 1
0
        protected override ITypeSymbol DetermineReturnTypeForSimpleNameOrMemberAccessExpression(
            ITypeInferenceService typeInferenceService,
            SemanticModel semanticModel,
            ExpressionSyntax expression,
            CancellationToken cancellationToken
            )
        {
            if (
                semanticModel.SyntaxTree.IsNameOfContext(
                    expression.SpanStart,
                    semanticModel,
                    cancellationToken
                    )
                )
            {
                return(typeInferenceService.InferType(
                           semanticModel,
                           expression,
                           true,
                           cancellationToken
                           ));
            }

            return(null);
        }
Exemplo n.º 2
0
        private static ITypeSymbol GetPropertyType(
            SimpleNameSyntax propertyName,
            SemanticModel semanticModel,
            ITypeInferenceService typeInference,
            CancellationToken cancellationToken
            )
        {
            if (propertyName.Parent is AssignmentExpressionSyntax parentAssignment)
            {
                return(typeInference.InferType(
                           semanticModel,
                           parentAssignment.Left,
                           objectAsDefault: true,
                           cancellationToken: cancellationToken
                           ));
            }

            if (propertyName.Parent is IsPatternExpressionSyntax isPatternExpression)
            {
                return(typeInference.InferType(
                           semanticModel,
                           isPatternExpression.Expression,
                           objectAsDefault: true,
                           cancellationToken: cancellationToken
                           ));
            }

            return(null);
        }
Exemplo n.º 3
0
		public MappingPage() : base("Fields mapping")
		{
			// This call is required by the Windows Form Designer.
			InitializeComponent();

			naming = ServiceRegistry.Instance[ typeof(INamingService) ] as INamingService;
			typeInference = ServiceRegistry.Instance[ typeof(ITypeInferenceService) ] as ITypeInferenceService;
		}
Exemplo n.º 4
0
        public MappingPage() : base("Fields mapping")
        {
            // This call is required by the Windows Form Designer.
            InitializeComponent();

            naming        = ServiceRegistry.Instance[typeof(INamingService)] as INamingService;
            typeInference = ServiceRegistry.Instance[typeof(ITypeInferenceService)] as ITypeInferenceService;
        }
		public void CorrectInference()
		{
			Kernel.AddComponent( "typeinf", typeof(ITypeInferenceService), typeof(TypeInferenceService) );

			ITypeInferenceService typeInf = Kernel[ typeof(ITypeInferenceService) ] as ITypeInferenceService;

			Assert.AreEqual( typeof(String), typeInf.ConvertOleType( OleDbType.VarChar ) );
			Assert.AreEqual( typeof(int), typeInf.ConvertOleType( OleDbType.Integer ) );
		}
Exemplo n.º 6
0
        private IEnumerable <INamedTypeSymbol>?FindNearestTupleConstructionWithInferrableType(
            SyntaxNode root,
            SemanticModel semanticModel,
            int position,
            SignatureHelpTriggerInfo triggerInfo,
            ITypeInferenceService typeInferrer,
            ISyntaxFactsService syntaxFacts,
            CancellationToken cancellationToken,
            out ExpressionSyntax?targetExpression
            )
        {
            // Walk upward through TupleExpressionSyntax/ParenthsizedExpressionSyntax looking for a
            // place where we can infer a tuple type.
            ParenthesizedExpressionSyntax?parenthesizedExpression = null;

            while (
                TryGetTupleExpression(
                    triggerInfo.TriggerReason,
                    root,
                    position,
                    syntaxFacts,
                    cancellationToken,
                    out var tupleExpression
                    ) ||
                TryGetParenthesizedExpression(
                    triggerInfo.TriggerReason,
                    root,
                    position,
                    syntaxFacts,
                    cancellationToken,
                    out parenthesizedExpression
                    )
                )
            {
                targetExpression = (ExpressionSyntax?)tupleExpression ?? parenthesizedExpression;
                var inferredTypes = typeInferrer.InferTypes(
                    semanticModel,
                    targetExpression !.SpanStart,
                    cancellationToken
                    );

                var tupleTypes = inferredTypes
                                 .Where(t => t.IsTupleType)
                                 .OfType <INamedTypeSymbol>()
                                 .ToList();
                if (tupleTypes.Any())
                {
                    return(tupleTypes);
                }

                position = targetExpression.GetFirstToken().SpanStart;
            }

            targetExpression = null;
            return(null);
        }
        private bool IsImplicitArrayCreation(SemanticModel semanticModel, SyntaxToken token, int position, ITypeInferenceService typeInferrer, CancellationToken cancellationToken)
        {
            if (token.IsKind(SyntaxKind.NewKeyword) && token.Parent.IsKind(SyntaxKind.ObjectCreationExpression))
            {
                var type = typeInferrer.InferType(semanticModel, token.Parent, objectAsDefault: false, cancellationToken: cancellationToken);
                return type != null && type is IArrayTypeSymbol;
            }

            return false;
        }
        public static INamedTypeSymbol InferDelegateType(
            this ITypeInferenceService typeInferenceService,
            SemanticModel semanticModel,
            SyntaxNode expression,
            CancellationToken cancellationToken)
        {
            var type = typeInferenceService.InferType(semanticModel, expression, objectAsDefault: false, cancellationToken: cancellationToken);

            return(type.GetDelegateType(semanticModel.Compilation));
        }
Exemplo n.º 9
0
        public static INamedTypeSymbol InferDelegateType(
            this ITypeInferenceService typeInferenceService,
            SemanticModel semanticModel,
            int position,
            CancellationToken cancellationToken)
        {
            var types = typeInferenceService.InferTypes(semanticModel, position, cancellationToken);

            return(GetFirstDelegateType(semanticModel, types));
        }
 public static ITypeSymbol?InferType(
     this ITypeInferenceService typeInferenceService,
     SemanticModel semanticModel,
     SyntaxNode expression,
     bool objectAsDefault,
     CancellationToken cancellationToken)
 {
     return(InferType(
                typeInferenceService, semanticModel, expression, objectAsDefault,
                name: null, cancellationToken: cancellationToken));
 }
Exemplo n.º 11
0
        public static INamedTypeSymbol InferDelegateType(
            this ITypeInferenceService typeInferenceService,
            SemanticModel semanticModel,
            SyntaxNode expression,
            CancellationToken cancellationToken)
        {
            var types         = typeInferenceService.InferTypes(semanticModel, expression, cancellationToken);
            var delegateTypes = types.Select(t => t.GetDelegateType(semanticModel.Compilation));

            return(delegateTypes.WhereNotNull().FirstOrDefault());
        }
Exemplo n.º 12
0
 public static ITypeSymbol InferType(
     this ITypeInferenceService typeInferenceService,
     SemanticModel semanticModel,
     int position,
     bool objectAsDefault,
     CancellationToken cancellationToken)
 {
     return(InferType(
                typeInferenceService, semanticModel, position, objectAsDefault,
                nameOpt: null, cancellationToken: cancellationToken));
 }
Exemplo n.º 13
0
 public static ImmutableArray <TypeInferenceInfo> GetTypeInferenceInfo(
     this ITypeInferenceService service,
     SemanticModel semanticModel,
     SyntaxNode expression,
     CancellationToken cancellationToken
     ) =>
 service.GetTypeInferenceInfo(
     semanticModel,
     expression,
     nameOpt: null,
     cancellationToken: cancellationToken
     );
Exemplo n.º 14
0
 public static ImmutableArray <ITypeSymbol> InferTypes(
     this ITypeInferenceService service,
     SemanticModel semanticModel,
     int position,
     CancellationToken cancellationToken
     ) =>
 service.InferTypes(
     semanticModel,
     position,
     nameOpt: null,
     cancellationToken: cancellationToken
     );
Exemplo n.º 15
0
        private ITypeSymbol GetPropertyType(
            SimpleNameSyntax property,
            SemanticModel semanticModel,
            ITypeInferenceService typeInference,
            CancellationToken cancellationToken)
        {
            var parent = property.Parent as AssignmentExpressionSyntax;

            if (parent != null)
            {
                return(typeInference.InferType(semanticModel, parent.Left, true, cancellationToken));
            }

            return(null);
        }
Exemplo n.º 16
0
        public static ITypeSymbol InferType(this ITypeInferenceService typeInferenceService,
                                            SemanticModel semanticModel,
                                            int position,
                                            bool objectAsDefault,
                                            CancellationToken cancellationToken)
        {
            var types = typeInferenceService.InferTypes(semanticModel, position, cancellationToken)
                        .WhereNotNull();

            if (!types.Any())
            {
                return(objectAsDefault ? semanticModel.Compilation.ObjectType : null);
            }

            return(types.FirstOrDefault());
        }
Exemplo n.º 17
0
        public static ITypeSymbol InferType(
            this ITypeInferenceService typeInferenceService,
            SemanticModel semanticModel,
            int position,
            bool objectAsDefault,
            string nameOpt,
            CancellationToken cancellationToken)
        {
            var types = typeInferenceService.InferTypes(semanticModel, position, nameOpt, cancellationToken);

            if (types.Length == 0)
            {
                return(objectAsDefault ? semanticModel.Compilation.ObjectType : null);
            }

            return(types.FirstOrDefault());
        }
        public static ITypeSymbol?InferType(
            this ITypeInferenceService typeInferenceService,
            SemanticModel semanticModel,
            SyntaxNode expression,
            bool objectAsDefault,
            string?name,
            CancellationToken cancellationToken)
        {
            var types = typeInferenceService.InferTypes(semanticModel, expression, name, cancellationToken);

            if (types.Length == 0)
            {
                return(objectAsDefault ? semanticModel.Compilation.ObjectType : null);
            }

            return(types.First());
        }
Exemplo n.º 19
0
        internal override bool TryGenerateProperty(
            SimpleNameSyntax propertyName,
            SemanticModel semanticModel,
            ITypeInferenceService typeInference,
            CancellationToken cancellationToken,
            out IPropertySymbol property)
        {
            property = null;
            var propertyType = GetPropertyType(propertyName, semanticModel, typeInference, cancellationToken);

            if (propertyType == null || propertyType is IErrorTypeSymbol)
            {
                property = CreatePropertySymbol(propertyName, semanticModel.Compilation.ObjectType);
                return(true);
            }

            property = CreatePropertySymbol(propertyName, propertyType);
            return(true);
        }
Exemplo n.º 20
0
            private static bool IsPossibleOutVariableDeclaration(SyntaxToken token, SemanticModel semanticModel, int position,
                                                                 ITypeInferenceService typeInferenceService, CancellationToken cancellationToken, out NameDeclarationInfo result)
            {
                if (!token.IsKind(SyntaxKind.IdentifierToken) || !(token.Parent.IsKind(SyntaxKind.IdentifierName)))
                {
                    result = default;
                    return(false);
                }

                var argument = token.Parent.Parent as ArgumentSyntax            // var is child of ArgumentSyntax, eg. Goo(out var $$
                               ?? token.Parent.Parent.Parent as ArgumentSyntax; // var is child of DeclarationExpression

                // under ArgumentSyntax, eg. Goo(out var a$$

                if (argument == null || !argument.RefOrOutKeyword.IsKind(SyntaxKind.OutKeyword))
                {
                    result = default;
                    return(false);
                }

                var type = typeInferenceService.InferType(semanticModel, argument.SpanStart, objectAsDefault: false, cancellationToken: cancellationToken);

                if (type != null)
                {
                    result = new NameDeclarationInfo(
                        ImmutableArray.Create(SymbolKind.Local),
                        Accessibility.NotApplicable,
                        new DeclarationModifiers(),
                        type,
                        alias: null);
                    return(true);
                }

                result = default;
                return(false);
            }
 protected abstract ITypeSymbol DetermineReturnTypeForSimpleNameOrMemberAccessExpression(ITypeInferenceService typeInferenceService, SemanticModel semanticModel, TExpressionSyntax expression, CancellationToken cancellationToken);
 internal abstract bool TryGenerateProperty(TSimpleNameSyntax propertyName, SemanticModel semanticModel, ITypeInferenceService typeInference, CancellationToken cancellationToken, out IPropertySymbol property);
        IEnumerable<INamedTypeSymbol> FindNearestTupleConstructionWithInferrableType(SyntaxNode root, SemanticModel semanticModel, int position, SignatureHelpTriggerInfo triggerInfo,
            ITypeInferenceService typeInferrer, ISyntaxFactsService syntaxFacts, CancellationToken cancellationToken, out ExpressionSyntax targetExpression)
        {
            // Walk upward through TupleExpressionSyntax/ParenthsizedExpressionSyntax looking for a 
            // place where we can infer a tuple type. 
            ParenthesizedExpressionSyntax parenthesizedExpression = null;
            while (TryGetTupleExpression(triggerInfo.TriggerReason, root, position, syntaxFacts, cancellationToken, out var tupleExpression) ||
                   TryGetParenthesizedExpression(triggerInfo.TriggerReason, root, position, syntaxFacts, cancellationToken, out parenthesizedExpression))
            {
                targetExpression = (ExpressionSyntax)tupleExpression ?? parenthesizedExpression;
                var inferredTypes = typeInferrer.InferTypes(semanticModel, targetExpression.SpanStart, cancellationToken);

                var tupleTypes = inferredTypes.Where(t => t.IsTupleType).OfType<INamedTypeSymbol>().ToList();
                if (tupleTypes.Any())
                {
                    return tupleTypes;
                }

                position = targetExpression.GetFirstToken().SpanStart;
            }

            targetExpression = null;
            return null;
        }
Exemplo n.º 24
0
 internal PythiaTypeInferenceServiceWrapper(ITypeInferenceService underlyingObject)
 => UnderlyingObject = underlyingObject;
        private static bool IsLambdaExpression(SemanticModel semanticModel, int position, SyntaxToken token, ITypeInferenceService typeInferrer, CancellationToken cancellationToken)
        {
            // Not after `new`
            if (token.IsKind(SyntaxKind.NewKeyword) && token.Parent.IsKind(SyntaxKind.ObjectCreationExpression))
            {
                return(false);
            }

            // Typing a generic type parameter, the tree might look like a binary expression around the < token.
            // If we infer a delegate type here (because that's what on the other side of the binop),
            // ignore it.
            if (token.Kind() == SyntaxKind.LessThanToken && token.Parent is BinaryExpressionSyntax)
            {
                return(false);
            }

            // We might be in the arguments to a parenthesized lambda
            if (token.Kind() == SyntaxKind.OpenParenToken || token.Kind() == SyntaxKind.CommaToken)
            {
                if (token.Parent != null && token.Parent is ParameterListSyntax)
                {
                    return(token.Parent.Parent != null && token.Parent.Parent is ParenthesizedLambdaExpressionSyntax);
                }
            }

            // A lambda that is being typed may be parsed as a tuple without names
            // For example, "(a, b" could be the start of either a tuple or lambda
            // But "(a: b, c" cannot be a lambda
            if (token.SyntaxTree.IsPossibleTupleContext(token, position) &&
                token.Parent.IsKind(SyntaxKind.TupleExpression, out TupleExpressionSyntax tupleExpression) &&
                !tupleExpression.HasNames())
            {
                position = token.Parent.SpanStart;
            }

            // Walk up a single level to allow for typing the beginning of a lambda:
            // new AssemblyLoadEventHandler(($$
            if (token.Kind() == SyntaxKind.OpenParenToken &&
                token.Parent.Kind() == SyntaxKind.ParenthesizedExpression)
            {
                position = token.Parent.SpanStart;
            }

            // WorkItem 834609: Automatic brace completion inserts the closing paren, making it
            // like a cast.
            if (token.Kind() == SyntaxKind.OpenParenToken &&
                token.Parent.Kind() == SyntaxKind.CastExpression)
            {
                position = token.Parent.SpanStart;
            }

            // In the following situation, the type inferrer will infer Task to support target type preselection
            // Action a = Task.$$
            // We need to explicitly exclude invocation/member access from suggestion mode
            var previousToken = token.GetPreviousTokenIfTouchingWord(position);

            if (previousToken.IsKind(SyntaxKind.DotToken) &&
                previousToken.Parent.IsKind(SyntaxKind.SimpleMemberAccessExpression))
            {
                return(false);
            }

            // async lambda:
            //    Goo(async($$
            //    Goo(async(p1, $$
            if (token.IsKind(SyntaxKind.OpenParenToken, SyntaxKind.CommaToken) && token.Parent.IsKind(SyntaxKind.ArgumentList) &&
                token.Parent.Parent is InvocationExpressionSyntax invocation &&
                invocation.Expression is IdentifierNameSyntax identifier)
            {
                if (identifier.Identifier.IsKindOrHasMatchingText(SyntaxKind.AsyncKeyword))
                {
                    return(true);
                }
            }

            // If we're an argument to a function with multiple overloads,
            // open the builder if any overload takes a delegate at our argument position
            var inferredTypeInfo = typeInferrer.GetTypeInferenceInfo(semanticModel, position, cancellationToken: cancellationToken);

            return(inferredTypeInfo.Any(type => GetDelegateType(type, semanticModel.Compilation).IsDelegateType()));
        }
        private bool IsLambdaExpression(SemanticModel semanticModel, int position, SyntaxToken token, ITypeInferenceService typeInferrer, CancellationToken cancellationToken)
        {
            // Typing a generic type parameter, the tree might look like a binary expression around the < token.
            // If we infer a delegate type here (because that's what on the other side of the binop), 
            // ignore it.
            if (token.Kind() == SyntaxKind.LessThanToken && token.Parent is BinaryExpressionSyntax)
            {
                return false;
            }

            // We might be in the arguments to a parenthsized lambda
            if (token.Kind() == SyntaxKind.OpenParenToken || token.Kind() == SyntaxKind.CommaToken)
            {
                if (token.Parent != null && token.Parent is ParameterListSyntax)
                {
                    return token.Parent.Parent != null && token.Parent.Parent is ParenthesizedLambdaExpressionSyntax;
                }
            }

            // Walk up a single level to allow for typing the beginning of a lambda:
            // new AssemblyLoadEventHandler(($$
            if (token.Kind() == SyntaxKind.OpenParenToken &&
                token.Parent.Kind() == SyntaxKind.ParenthesizedExpression)
            {
                position = token.Parent.SpanStart;
            }

            // WorkItem 834609: Automatic brace completion inserts the closing paren, making it
            // like a cast.
            if (token.Kind() == SyntaxKind.OpenParenToken &&
                token.Parent.Kind() == SyntaxKind.CastExpression)
            {
                position = token.Parent.SpanStart;
            }

            // If we're an argument to a function with multiple overloads, 
            // open the builder if any overload takes a delegate at our argument position
            var inferredTypes = typeInferrer.InferTypes(semanticModel, position, cancellationToken: cancellationToken);

            return inferredTypes.Any(type => type.GetDelegateType(semanticModel.Compilation).IsDelegateType());
        }
Exemplo n.º 27
0
 protected abstract ITypeSymbol CanGenerateMethodForSimpleNameOrMemberAccessExpression(ITypeInferenceService typeInferenceService, SemanticModel semanticModel, TExpressionSyntax expression, CancellationToken cancellationToken);
Exemplo n.º 28
0
        private bool IsLambdaExpression(SemanticModel semanticModel, int position, SyntaxToken token, ITypeInferenceService typeInferrer, CancellationToken cancellationToken)
        {
            // Typing a generic type parameter, the tree might look like a binary expression around the < token.
            // If we infer a delegate type here (because that's what on the other side of the binop),
            // ignore it.
            if (token.Kind() == SyntaxKind.LessThanToken && token.Parent is BinaryExpressionSyntax)
            {
                return(false);
            }

            // We might be in the arguments to a parenthesized lambda
            if (token.Kind() == SyntaxKind.OpenParenToken || token.Kind() == SyntaxKind.CommaToken)
            {
                if (token.Parent != null && token.Parent is ParameterListSyntax)
                {
                    return(token.Parent.Parent != null && token.Parent.Parent is ParenthesizedLambdaExpressionSyntax);
                }
            }

            // Walk up a single level to allow for typing the beginning of a lambda:
            // new AssemblyLoadEventHandler(($$
            if (token.Kind() == SyntaxKind.OpenParenToken &&
                token.Parent.Kind() == SyntaxKind.ParenthesizedExpression)
            {
                position = token.Parent.SpanStart;
            }

            // WorkItem 834609: Automatic brace completion inserts the closing paren, making it
            // like a cast.
            if (token.Kind() == SyntaxKind.OpenParenToken &&
                token.Parent.Kind() == SyntaxKind.CastExpression)
            {
                position = token.Parent.SpanStart;
            }

            // If we're an argument to a function with multiple overloads,
            // open the builder if any overload takes a delegate at our argument position
            var inferredTypes = typeInferrer.InferTypes(semanticModel, position, cancellationToken: cancellationToken);

            return(inferredTypes.Any(type => type.GetDelegateType(semanticModel.Compilation).IsDelegateType()));
        }
 public PlainFieldInferenceService(INamingService namingService, ITypeInferenceService typeInfService)
 {
     _namingService  = namingService;
     _typeInfService = typeInfService;
 }
Exemplo n.º 30
0
        private bool IsImplicitArrayCreation(SemanticModel semanticModel, SyntaxToken token, int position, ITypeInferenceService typeInferrer, CancellationToken cancellationToken)
        {
            if (token.IsKind(SyntaxKind.NewKeyword) && token.Parent.IsKind(SyntaxKind.ObjectCreationExpression))
            {
                var type = typeInferrer.InferType(semanticModel, token.Parent, objectAsDefault: false, cancellationToken: cancellationToken);
                return(type != null && type is IArrayTypeSymbol);
            }

            return(false);
        }
Exemplo n.º 31
0
		public PlainFieldInferenceService(INamingService namingService, ITypeInferenceService typeInfService)
		{
			_namingService = namingService;
			_typeInfService = typeInfService;
		}
        private bool IsLambdaExpression(SemanticModel semanticModel, int position, SyntaxToken token, ITypeInferenceService typeInferrer, CancellationToken cancellationToken)
        {
            // Typing a generic type parameter, the tree might look like a binary expression around the < token.
            // If we infer a delegate type here (because that's what on the other side of the binop), 
            // ignore it.
            if (token.Kind() == SyntaxKind.LessThanToken && token.Parent is BinaryExpressionSyntax)
            {
                return false;
            }

            // We might be in the arguments to a parenthesized lambda
            if (token.Kind() == SyntaxKind.OpenParenToken || token.Kind() == SyntaxKind.CommaToken)
            {
                if (token.Parent != null && token.Parent is ParameterListSyntax)
                {
                    return token.Parent.Parent != null && token.Parent.Parent is ParenthesizedLambdaExpressionSyntax;
                }
            }

            // A lambda that is being typed may be parsed as a tuple without names
            // For example, "(a, b" could be the start of either a tuple or lambda
            // But "(a: b, c" cannot be a lambda
            if (token.SyntaxTree.IsPossibleTupleContext(token, position) && token.Parent.IsKind(SyntaxKind.TupleExpression) &&
               !((TupleExpressionSyntax)token.Parent).HasNames())
            {
                position = token.Parent.SpanStart;
            }

            // Walk up a single level to allow for typing the beginning of a lambda:
            // new AssemblyLoadEventHandler(($$
            if (token.Kind() == SyntaxKind.OpenParenToken &&
                token.Parent.Kind() == SyntaxKind.ParenthesizedExpression)
            {
                position = token.Parent.SpanStart;
            }

            // WorkItem 834609: Automatic brace completion inserts the closing paren, making it
            // like a cast.
            if (token.Kind() == SyntaxKind.OpenParenToken &&
                token.Parent.Kind() == SyntaxKind.CastExpression)
            {
                position = token.Parent.SpanStart;
            }

            // If we're an argument to a function with multiple overloads, 
            // open the builder if any overload takes a delegate at our argument position
            var inferredTypeInfo = typeInferrer.GetTypeInferenceInfo(semanticModel, position, cancellationToken: cancellationToken);

            return inferredTypeInfo.Any(type => GetDelegateType(type, semanticModel.Compilation).IsDelegateType());
        }
Exemplo n.º 33
0
        private bool IsLambdaExpression(SemanticModel semanticModel, int position, SyntaxToken token, ITypeInferenceService typeInferrer, CancellationToken cancellationToken)
        {
            // Typing a generic type parameter, the tree might look like a binary expression around the < token.
            // If we infer a delegate type here (because that's what on the other side of the binop),
            // ignore it.
            if (token.Kind() == SyntaxKind.LessThanToken && token.Parent is BinaryExpressionSyntax)
            {
                return(false);
            }

            // We might be in the arguments to a parenthesized lambda
            if (token.Kind() == SyntaxKind.OpenParenToken || token.Kind() == SyntaxKind.CommaToken)
            {
                if (token.Parent != null && token.Parent is ParameterListSyntax)
                {
                    return(token.Parent.Parent != null && token.Parent.Parent is ParenthesizedLambdaExpressionSyntax);
                }
            }

            // A lambda that is being typed may be parsed as a tuple without names
            // For example, "(a, b" could be the start of either a tuple or lambda
            // But "(a: b, c" cannot be a lambda
            if (token.IsPossibleTupleElementNameContext(position) && token.Parent.IsKind(SyntaxKind.TupleExpression) &&
                !((TupleExpressionSyntax)token.Parent).HasNames())
            {
                position = token.Parent.SpanStart;
            }

            // Walk up a single level to allow for typing the beginning of a lambda:
            // new AssemblyLoadEventHandler(($$
            if (token.Kind() == SyntaxKind.OpenParenToken &&
                token.Parent.Kind() == SyntaxKind.ParenthesizedExpression)
            {
                position = token.Parent.SpanStart;
            }

            // WorkItem 834609: Automatic brace completion inserts the closing paren, making it
            // like a cast.
            if (token.Kind() == SyntaxKind.OpenParenToken &&
                token.Parent.Kind() == SyntaxKind.CastExpression)
            {
                position = token.Parent.SpanStart;
            }

            // If we're an argument to a function with multiple overloads,
            // open the builder if any overload takes a delegate at our argument position
            var inferredTypeInfo = typeInferrer.GetTypeInferenceInfo(semanticModel, position, cancellationToken: cancellationToken);

            return(inferredTypeInfo.Any(type => GetDelegateType(type, semanticModel.Compilation).IsDelegateType()));
        }