public override async Task ProvideCompletionsAsync(CompletionContext context)
        {
            if (await IsWatchWindowAsync(context).ConfigureAwait(false))
            {
                // Completions are not usable in watch window
                return;
            }

            var syntaxContext = await SyntaxContext.CreateAsync(context.Document, context.Position, context.CancellationToken)
                                .ConfigureAwait(false);

            var applicableTypeProviders = typeCompletionProviders
                                          .Where(p => p.IsApplicable(syntaxContext, Options))
                                          .ToArray();

            if (applicableTypeProviders.Length > 0)
            {
                var typeCompletions = GetAllTypes(syntaxContext, Options)
                                      .SelectMany(type => applicableTypeProviders
                                                  .Select(provider => provider.GetCompletionItemsForType(type, syntaxContext, Options)))
                                      .Where(enumerable => enumerable != null)
                                      .SelectMany(enumerable => enumerable);

                context.AddItems(typeCompletions);
            }

            var simpleCompletions = simpleCompletionProviders
                                    .Where(p => p.IsApplicable(syntaxContext, Options))
                                    .Select(provider => provider.GetCompletionItems(syntaxContext, Options))
                                    .Where(enumerable => enumerable != null)
                                    .SelectMany(enumerable => enumerable);

            context.AddItems(simpleCompletions);
        }
Exemplo n.º 2
0
        public override async Task ProvideCompletionsAsync(CompletionContext context)
        {
            try
            {
                if (Options == null)
                {
                    // Package not loaded yet (e.g. no solution opened)
                    return;
                }
                if (await IsWatchWindowAsync(context).ConfigureAwait(false))
                {
                    // Completions are not usable in watch window
                    return;
                }

                if (IsRazorView(context))
                {
                    // Completions are not usable in cshtml-Razor Views. Insertion of Namespaces doesn't work there.
                    return;
                }

                var syntaxContext = await SyntaxContext.CreateAsync(context.Document, context.Position, context.CancellationToken)
                                    .ConfigureAwait(false);

                var applicableTypeProviders = typeCompletionProviders
                                              .Where(p => p.IsApplicable(syntaxContext, Options))
                                              .ToArray();
                if (applicableTypeProviders.Length > 0)
                {
                    var typeCompletions = SymbolNavigator.GetAllTypes(syntaxContext, Options)
                                          .SelectMany(type => applicableTypeProviders
                                                      .Select(provider => provider.GetCompletionItemsForType(type, syntaxContext, Options)))
                                          .Where(enumerable => enumerable != null)
                                          .SelectMany(enumerable => enumerable);

                    context.AddItems(typeCompletions);
                }

                var simpleCompletions = simpleCompletionProviders
                                        .Where(p => p.IsApplicable(syntaxContext, Options))
                                        .Select(provider => provider.GetCompletionItems(syntaxContext, Options))
                                        .Where(enumerable => enumerable != null)
                                        .SelectMany(enumerable => enumerable);

                context.AddItems(simpleCompletions);

                // If Completion was triggered by this provider - use suggestion mode
                if (_triggeredByUs && context.SuggestionModeItem == null)
                {
                    context.SuggestionModeItem = CompletionItem.Create("");
                }
            }
            finally
            {
                _triggeredByUs = false;
            }
        }
Exemplo n.º 3
0
        public override async Task ProvideCompletionsAsync(CompletionContext context)
        {
            try
            {
                if (Options == null)
                {
                    // Package not loaded yet (e.g. no solution opened)
                    return;
                }
                if (await IsWatchWindowAsync(context).ConfigureAwait(false))
                {
                    // Completions are not usable in watch window
                    return;
                }

                if (IsRazorView(context))
                {
                    // Completions are not usable in cshtml-Razor Views. Insertion of Namespaces doesn't work there.
                    return;
                }

                var syntaxContext = await SyntaxContext.CreateAsync(context.Document, context.Position, context.CancellationToken)
                                    .ConfigureAwait(false);

                if (syntaxContext == null)
                {
                    return;
                }

                var completionsTasks = completionProviders
                                       .Where(p => p.IsApplicable(syntaxContext, Options))
                                       .Select(provider => provider.GetCompletionItemsAsync(syntaxContext, Options));

                var completions = (await Task.WhenAll(completionsTasks).ConfigureAwait(false)).SelectMany(i => i);

                context.AddItems(completions);

                // If Completion was triggered by this provider - use suggestion mode
                if (_triggeredByUs && context.SuggestionModeItem == null)
                {
                    context.SuggestionModeItem = CompletionItem.Create("");
                }
            }
            finally
            {
                _triggeredByUs = false;
            }
        }