Beispiel #1
0
        public async Task <CompletionResult> GetCompletionData(int position, char?triggerChar)
        {
            IList <ICompletionDataEx> completionData   = null;
            IOverloadProvider         overloadProvider = null;
            bool?isCompletion = null;

            if (triggerChar != null)
            {
                var isSignatureHelp = await _interactiveManager.IsSignatureHelpTriggerCharacter(position - 1).ConfigureAwait(false);

                if (isSignatureHelp)
                {
                    var signatureHelp = await _interactiveManager.GetSignatureHelp(
                        new SignatureHelpTriggerInfo(SignatureHelpTriggerReason.TypeCharCommand, triggerChar.Value), position)
                                        .ConfigureAwait(false);

                    if (signatureHelp != null)
                    {
                        overloadProvider = new RoslynOverloadProvider(signatureHelp);
                    }
                }
                else
                {
                    isCompletion = await _interactiveManager.IsCompletionTriggerCharacter(position - 1).ConfigureAwait(false);
                }
            }

            if (overloadProvider == null && isCompletion != false)
            {
                var items = await _interactiveManager.GetCompletion(
                    triggerChar != null
                    ?CompletionTriggerInfo.CreateTypeCharTriggerInfo(triggerChar.Value)
                    : CompletionTriggerInfo.CreateInvokeCompletionTriggerInfo(),
                    position).ConfigureAwait(false);

                completionData = items.Select(item => new AvalonEditCompletionData(item)).ToArray <ICompletionDataEx>();
            }

            return(new CompletionResult(completionData, overloadProvider));
        }
        public async Task<CompletionResult> GetCompletionData(int position, char? triggerChar)
        {
            IList<ICompletionDataEx> completionData = null;
            IOverloadProvider overloadProvider = null;
            bool? isCompletion = null;

            if (triggerChar != null)
            {
                var isSignatureHelp = await _interactiveManager.IsSignatureHelpTriggerCharacter(position - 1).ConfigureAwait(false);
                if (isSignatureHelp)
                {
                    var signatureHelp = await _interactiveManager.GetSignatureHelp(
                        new SignatureHelpTriggerInfo(SignatureHelpTriggerReason.TypeCharCommand, triggerChar.Value), position)
                        .ConfigureAwait(false);
                    if (signatureHelp != null)
                    {
                        overloadProvider = new RoslynOverloadProvider(signatureHelp);
                    }
                }
                else
                {
                    isCompletion = await _interactiveManager.IsCompletionTriggerCharacter(position - 1).ConfigureAwait(false);
                }
            }

            if (overloadProvider == null && isCompletion != false)
            {
                var items = await _interactiveManager.GetCompletion(
                    triggerChar != null
                        ? CompletionTriggerInfo.CreateTypeCharTriggerInfo(triggerChar.Value)
                        : CompletionTriggerInfo.CreateInvokeCompletionTriggerInfo(),
                    position).ConfigureAwait(false);
                completionData = items.Select(item => new AvalonEditCompletionData(item)).ToArray<ICompletionDataEx>();
            }

            return new CompletionResult(completionData, overloadProvider);
        }
Beispiel #3
0
        public async Task <CompletionResult> GetCompletionData(int position, char?triggerChar, bool useSignatureHelp)
        {
            IList <ICompletionDataEx> completionData   = null;
            IOverloadProviderEx       overloadProvider = null;
            var useHardSelection = true;

            var document = _roslynHost.GetDocument(_documentId);

            if (useSignatureHelp || triggerChar != null)
            {
                var signatureHelpProvider = _roslynHost.GetService <ISignatureHelpProvider>();
                var isSignatureHelp       = useSignatureHelp || signatureHelpProvider.IsTriggerCharacter(triggerChar.Value);
                if (isSignatureHelp)
                {
                    var signatureHelp = await signatureHelpProvider.GetItemsAsync(
                        document,
                        position,
                        new SignatureHelpTriggerInfo(
                            useSignatureHelp
                                ? SignatureHelpTriggerReason.InvokeSignatureHelpCommand
                                : SignatureHelpTriggerReason.TypeCharCommand, triggerChar))
                                        .ConfigureAwait(false);

                    if (signatureHelp != null)
                    {
                        overloadProvider = new RoslynOverloadProvider(signatureHelp);
                    }
                }
            }

            if (overloadProvider == null)
            {
                var completionService = CompletionService.GetService(document);
                var completionTrigger = GetCompletionTrigger(triggerChar);
                var data = await completionService.GetCompletionsAsync(
                    document,
                    position,
                    completionTrigger
                    ).ConfigureAwait(false);

                if (data != null && data.Items.Any())
                {
                    useHardSelection = data.SuggestionModeItem == null;
                    var helper = CompletionHelper.GetHelper(document, completionService);
                    var text   = await document.GetTextAsync().ConfigureAwait(false);

                    var textSpanToText = new Dictionary <TextSpan, string>();

                    completionData = data.Items
                                     .Where(item => MatchesFilterText(helper, item, text, textSpanToText))
                                     .Select(item => new RoslynCompletionData(document, item, triggerChar, _snippetService.SnippetManager))
                                     .ToArray <ICompletionDataEx>();
                }
                else
                {
                    completionData = Array.Empty <ICompletionDataEx>();
                }
            }

            return(new CompletionResult(completionData, overloadProvider, useHardSelection));
        }