public async Task <CompletionResult> GetCompletionDataAsync(CompletionContext completionContext, CompletionTriggerInfo info, CancellationToken cancellationToken = default(CancellationToken)) { if (completionContext == null) { throw new ArgumentNullException("completionContext"); } var document = completionContext.Document; var semanticModel = await completionContext.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); var position = completionContext.Position; var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var ctx = await completionContext.GetSyntaxContextAsync(workspace, cancellationToken); ctx.SemanticModel = semanticModel; // case lambda parameter (n1, $ if (ctx.TargetToken.IsKind(SyntaxKind.CommaToken) && ctx.TargetToken.Parent != null && ctx.TargetToken.Parent.Parent != null && ctx.TargetToken.Parent.Parent.IsKind(SyntaxKind.ParenthesizedLambdaExpression)) { return(CompletionResult.Empty); } var result = new CompletionResult { SyntaxContext = ctx }; if (position > 0) { var nonExclusiveHandlers = new List <CompletionContextHandler> (); var exclusiveHandlers = new List <CompletionContextHandler> (); var toRetriggerHandlers = new List <CompletionContextHandler> (); IEnumerable <CompletionContextHandler> handlerList; if (completionContext.UseDefaultContextHandlers) { handlerList = handlers.Concat(completionContext.AdditionalContextHandlers); } else { handlerList = completionContext.AdditionalContextHandlers; } foreach (var handler in handlerList) { if (info.CompletionTriggerReason == CompletionTriggerReason.CompletionCommand || info.CompletionTriggerReason == CompletionTriggerReason.BackspaceOrDeleteCommand || handler.IsTriggerCharacter(text, position - 1)) { if (await handler.IsExclusiveAsync(completionContext, ctx, info, cancellationToken)) { exclusiveHandlers.Add(handler); } else { nonExclusiveHandlers.Add(handler); } } else { toRetriggerHandlers.Add(handler); } } foreach (var handler in exclusiveHandlers) { var handlerResult = await handler.GetCompletionDataAsync(result, this, completionContext, info, ctx, cancellationToken); //if (handlerResult != null) { // Console.WriteLine ("-----" + handler); // foreach (var item in handlerResult) { // Console.WriteLine (item.DisplayText); // } //} else { // Console.WriteLine ("-----" + handler + " == NULL"); //} if (handlerResult != null) { result.AddRange(handlerResult); } } if (result.Count == 0) { foreach (var handler in nonExclusiveHandlers) { var handlerResult = await handler.GetCompletionDataAsync(result, this, completionContext, info, ctx, cancellationToken); //if (handlerResult != null) { // Console.WriteLine ("-----" + handler); // foreach (var item in handlerResult) { // Console.WriteLine (item.DisplayText); // } //} else { // Console.WriteLine ("-----" + handler + " == NULL"); //} if (handlerResult != null && handlerResult.Any()) { result.AddRange(handlerResult); } else { toRetriggerHandlers.Add(handler); } } if (result.Count > 0) { info = info.WithCompletionTriggerReason(CompletionTriggerReason.RetriggerCommand); foreach (var handler in toRetriggerHandlers) { var handlerResult = await handler.GetCompletionDataAsync(result, this, completionContext, info, ctx, cancellationToken); if (handlerResult != null) { result.AddRange(handlerResult); } } } } } // prevent auto selection for "<number>." case if (ctx.TargetToken.IsKind(SyntaxKind.DotToken)) { var accessExpr = ctx.TargetToken.Parent as MemberAccessExpressionSyntax; if (accessExpr != null && accessExpr.Expression != null && accessExpr.Expression.IsKind(SyntaxKind.NumericLiteralExpression)) { result.AutoSelect = false; } } if (ctx.LeftToken.Parent != null && ctx.LeftToken.Parent.Parent != null && ctx.TargetToken.Parent != null && !ctx.TargetToken.Parent.IsKind(SyntaxKind.NameEquals) && ctx.LeftToken.Parent.Parent.IsKind(SyntaxKind.AnonymousObjectMemberDeclarator)) { result.AutoSelect = false; } if (ctx.TargetToken.IsKind(SyntaxKind.OpenParenToken) && ctx.TargetToken.GetPreviousToken().IsKind(SyntaxKind.OpenParenToken)) { var validTypes = TypeGuessing.GetValidTypes(semanticModel, ctx.TargetToken.Parent, cancellationToken); result.AutoSelect = !validTypes.Any(t => t.IsDelegateType()); } foreach (var type in ctx.InferredTypes) { if (type.TypeKind == TypeKind.Delegate) { result.AutoSelect = false; break; } } if (ctx.CSharpSyntaxContext.IsPossibleTupleContext) { result.AutoSelect = false; } return(result); }
public async Task<CompletionResult> GetCompletionDataAsync(CompletionContext completionContext, CompletionTriggerInfo info, CancellationToken cancellationToken = default(CancellationToken)) { if (completionContext == null) throw new ArgumentNullException ("completionContext"); var document = completionContext.Document; var semanticModel = await completionContext.GetSemanticModelAsync (cancellationToken).ConfigureAwait(false); var position = completionContext.Position; var text = await document.GetTextAsync (cancellationToken).ConfigureAwait (false); var ctx = await completionContext.GetSyntaxContextAsync (workspace, cancellationToken); ctx.SemanticModel = semanticModel; // case lambda parameter (n1, $ if (ctx.TargetToken.IsKind (SyntaxKind.CommaToken) && ctx.TargetToken.Parent != null && ctx.TargetToken.Parent.Parent != null && ctx.TargetToken.Parent.Parent.IsKind(SyntaxKind.ParenthesizedLambdaExpression)) return CompletionResult.Empty; var result = new CompletionResult { SyntaxContext = ctx }; if (position > 0) { var nonExclusiveHandlers = new List<CompletionContextHandler> (); var exclusiveHandlers = new List<CompletionContextHandler> (); var toRetriggerHandlers = new List<CompletionContextHandler> (); IEnumerable<CompletionContextHandler> handlerList; if (completionContext.UseDefaultContextHandlers) { handlerList = handlers.Concat (completionContext.AdditionalContextHandlers); } else { handlerList = completionContext.AdditionalContextHandlers; } foreach (var handler in handlerList) { if (info.CompletionTriggerReason == CompletionTriggerReason.CompletionCommand || handler.IsTriggerCharacter (text, position - 1)) { if (await handler.IsExclusiveAsync (completionContext, ctx, info, cancellationToken)) { exclusiveHandlers.Add (handler); } else { nonExclusiveHandlers.Add (handler); } } else { toRetriggerHandlers.Add (handler); } } foreach (var handler in exclusiveHandlers) { var handlerResult = handler.GetCompletionDataAsync (result, this, completionContext, info, ctx, cancellationToken).Result; //if (handlerResult != null) { // Console.WriteLine ("-----" + handler); // foreach (var item in handlerResult) { // Console.WriteLine (item.DisplayText); // } //} else { // Console.WriteLine ("-----" + handler + " == NULL"); //} if (handlerResult != null) result.AddRange (handlerResult); } if (result.Count == 0) { foreach (var handler in nonExclusiveHandlers) { var handlerResult = await handler.GetCompletionDataAsync (result, this, completionContext, info, ctx, cancellationToken); //if (handlerResult != null) { // Console.WriteLine ("-----" + handler); // foreach (var item in handlerResult) { // Console.WriteLine (item.DisplayText); // } //} else { // Console.WriteLine ("-----" + handler + " == NULL"); //} if (handlerResult != null && handlerResult.Any ()) { result.AddRange (handlerResult); } else { toRetriggerHandlers.Add (handler); } } if (result.Count > 0) { info = info.WithCompletionTriggerReason (CompletionTriggerReason.RetriggerCommand); foreach (var handler in toRetriggerHandlers) { var handlerResult = await handler.GetCompletionDataAsync (result, this, completionContext, info, ctx, cancellationToken); if (handlerResult != null) result.AddRange (handlerResult); } } } } // prevent auto selection for "<number>." case if (ctx.TargetToken.IsKind(SyntaxKind.DotToken)) { var accessExpr = ctx.TargetToken.Parent as MemberAccessExpressionSyntax; if (accessExpr != null && accessExpr.Expression != null && accessExpr.Expression.IsKind(SyntaxKind.NumericLiteralExpression)) { result.AutoSelect = false; } } if (ctx.LeftToken.Parent != null && ctx.LeftToken.Parent.Parent != null && ctx.TargetToken.Parent != null && !ctx.TargetToken.Parent.IsKind(SyntaxKind.NameEquals) && ctx.LeftToken.Parent.Parent.IsKind(SyntaxKind.AnonymousObjectMemberDeclarator)) result.AutoSelect = false; if (ctx.TargetToken.IsKind (SyntaxKind.OpenParenToken) && ctx.TargetToken.GetPreviousToken ().IsKind (SyntaxKind.OpenParenToken)) { var validTypes = TypeGuessing.GetValidTypes (semanticModel, ctx.TargetToken.Parent, cancellationToken); result.AutoSelect = !validTypes.Any (t => t.IsDelegateType ()); } foreach (var type in ctx.InferredTypes) { if (type.TypeKind == TypeKind.Delegate) { result.AutoSelect = false; break; } } return result; }