Пример #1
0
        private void SetCompletionData(CodeCompletionResults completionData)
        {
            if (_shell.DebugMode)
            {
                _console.WriteLine(completionData.Contexts.ToString());
            }

            if (!completionData.Contexts.HasFlag(CompletionContext.NaturalLanguage) && (completionData.Contexts != CompletionContext.Unexposed || completionData.Contexts == CompletionContext.Unknown))
            {
                if (IncludeSnippets && !(completionData.Contexts.HasFlag(CompletionContext.ArrowMemberAccess) || completionData.Contexts.HasFlag(CompletionContext.DotMemberAccess)))
                {
                    InsertSnippets(completionData.Completions);
                }

                foreach (var result in completionData.Completions)
                {
                    CompletionDataViewModel currentCompletion = null;

                    currentCompletion = unfilteredCompletions.BinarySearch(c => c.Title, result.Suggestion);

                    if (currentCompletion == null)
                    {
                        unfilteredCompletions.Add(new CompletionDataViewModel(result));
                    }
                    else
                    {
                        currentCompletion.Overloads++;
                    }
                }
            }
        }
Пример #2
0
        private void SetCompletionData(CodeCompletionResults completionData)
        {
            if (_studio.DebugMode)
            {
                _console.WriteLine(completionData.Contexts.ToString());
            }

            if (completionData.StartOffset.HasValue)
            {
                _recommendedInsertionOffset = completionData.StartOffset;
            }
            else
            {
                _recommendedInsertionOffset = null;
            }

            if (!completionData.Contexts.HasFlag(CompletionContext.NaturalLanguage) && (completionData.Contexts != CompletionContext.Unexposed || completionData.Contexts == CompletionContext.Unknown))
            {
                if (IncludeSnippets && !(completionData.Contexts.HasFlag(CompletionContext.ArrowMemberAccess) || completionData.Contexts.HasFlag(CompletionContext.DotMemberAccess)))
                {
                    InsertSnippets(completionData.Completions);
                }

                recommendedCompletion = null;

                foreach (var result in completionData.Completions)
                {
                    CompletionDataViewModel currentCompletion = null;

                    currentCompletion = unfilteredCompletions.BinarySearch(c => c.FilterText, result.FilterText);

                    if (currentCompletion == null)
                    {
                        currentCompletion = new CompletionDataViewModel(result);
                        unfilteredCompletions.Add(currentCompletion);
                    }
                    else
                    {
                        currentCompletion.Overloads++;
                    }

                    if (result.SelectionBehavior != CompletionItemSelectionBehavior.Default)
                    {
                        if (recommendedCompletion == null || (recommendedCompletion != null && result.Priority > recommendedCompletion.Priority))
                        {
                            recommendedCompletion = currentCompletion;
                        }
                    }
                }
            }
        }
Пример #3
0
        private void SetCompletionData(List<CodeCompletionData> completionData)
        {
            unfilteredCompletions.Clear();

            foreach (var result in completionData)
            {
                CompletionDataViewModel currentCompletion = null;

                currentCompletion = unfilteredCompletions.BinarySearch(c => c.Title, result.Suggestion);

                if (currentCompletion == null)
                {
                    unfilteredCompletions.Add(CompletionDataViewModel.Create(result));
                }
                else
                {
                    currentCompletion.Overloads++;
                }
            }
        }
Пример #4
0
        private void SetCompletionData(CodeCompletionResults completionData)
        {
            unfilteredCompletions.Clear();

            if (completionData.Contexts != CompletionContext.Unexposed)
            {
                foreach (var result in completionData.Completions)
                {
                    CompletionDataViewModel currentCompletion = null;

                    currentCompletion = unfilteredCompletions.BinarySearch(c => c.Title, result.Suggestion);

                    if (currentCompletion == null)
                    {
                        unfilteredCompletions.Add(CompletionDataViewModel.Create(result));
                    }
                    else
                    {
                        currentCompletion.Overloads++;
                    }
                }
            }
        }
Пример #5
0
        private void UpdateFilter(int caretIndex)
        {
            if (caretIndex > intellisenseStartedAt)
            {
                Dispatcher.UIThread.InvokeTaskAsync(() =>
                {
                    currentFilter = editor.TextDocument.GetText(intellisenseStartedAt, caretIndex - intellisenseStartedAt).Replace(".", string.Empty);
                }).Wait();
            }
            else
            {
                currentFilter = string.Empty;
            }

            CompletionDataViewModel suggestion = null;

            var filteredResults = unfilteredCompletions as IEnumerable<CompletionDataViewModel>;

            if (currentFilter != string.Empty)
            {
                filteredResults = unfilteredCompletions.Where(c => c != null && c.Title.ToLower().Contains(currentFilter.ToLower()));

                IEnumerable<CompletionDataViewModel> newSelectedCompletions = null;

                newSelectedCompletions = filteredResults.Where(s => s.Title.StartsWith(currentFilter));
                // try find exact match case sensitive

                if (newSelectedCompletions.Count() == 0)
                {
                    newSelectedCompletions = filteredResults.Where(s => s.Title.ToLower().StartsWith(currentFilter.ToLower()));
                    // try find non-case sensitve match
                }

                if (newSelectedCompletions.Count() == 0)
                {
                    suggestion = noSelectedCompletion;
                }
                else
                {
                    var newSelectedCompletion = newSelectedCompletions.FirstOrDefault();

                    suggestion = newSelectedCompletion;
                }
            }
            else
            {
                suggestion = noSelectedCompletion;
            }

            if (filteredResults?.Count() > 0)
            {
                if (filteredResults?.Count() == 1 && filteredResults.First().Title == currentFilter)
                {
                    CloseIntellisense();
                }
                else
                {
                    var list = filteredResults.ToList();

                    Dispatcher.UIThread.InvokeTaskAsync(() =>
                    {
                        intellisenseControl.CompletionData = null;
                        intellisenseControl.CompletionData = list;
                        intellisenseControl.SelectedCompletion = suggestion;
                        intellisenseControl.IsVisible = true;
                    }).Wait();
                }
            }
            else
            {
                Dispatcher.UIThread.InvokeTaskAsync(() =>
                {
                    intellisenseControl.SelectedCompletion = noSelectedCompletion;
                });
            }
        }
Пример #6
0
        public async Task OnKeyUp(KeyEventArgs e)
        {
            var isVisible  = intellisenseControl.IsVisible;
            var caretIndex = editor.CaretIndex;

            var caretChar             = '\0';
            var behindCaretChar       = '\0';
            var behindBehindCaretChar = '\0';

            await Dispatcher.UIThread.InvokeTaskAsync(() =>
            {
                if (caretIndex > 1 && caretIndex < editor.TextDocument.TextLength)
                {
                    behindBehindCaretChar = editor.TextDocument.GetCharAt(caretIndex - 2);
                }

                if (caretIndex > 0 && caretIndex < editor.TextDocument.TextLength)
                {
                    caretChar = editor.TextDocument.GetCharAt(caretIndex);
                }

                if (caretIndex > 0 && caretIndex <= editor.TextDocument.TextLength)
                {
                    behindCaretChar = editor.TextDocument.GetCharAt(caretIndex - 1);
                }
            });

            await CompletionAssistantOnKeyUp(behindCaretChar, behindBehindCaretChar);

            if (e.Key == Key.Escape && e.Modifiers == InputModifiers.None)
            {
                await Dispatcher.UIThread.InvokeTaskAsync(() =>
                {
                    if (completionAssistant.IsVisible)
                    {
                        completionAssistant.Close();
                    }
                    else if (intellisenseControl.IsVisible)
                    {
                        Close();
                    }
                });
            }

            if (IsIntellisenseKey(e))
            {
                if (caretIndex <= intellisenseStartedAt)
                {
                    await Dispatcher.UIThread.InvokeTaskAsync(() => { Close(); });

                    return;
                }

                if (IsIntellisenseResetKey(e))
                {
                    isVisible = false; // We dont actually want to hide, so use backing field.
                                       //currentFilter = string.Empty;
                }

                await Dispatcher.UIThread.InvokeTaskAsync(async() => { await CompleteOnKeyUp(); });

                IEnumerable <CompletionDataViewModel> filteredResults = null;

                if (!intellisenseControl.IsVisible && (IsIntellisenseOpenKey(e) || IsIntellisenseResetKey(e)))
                {
                    var caret = new TextLocation();

                    var behindStartChar = '\0';

                    if (behindCaretChar == ':' && behindBehindCaretChar == ':')
                    {
                        intellisenseStartedAt = caretIndex;
                        intellisenseEndsAt    = intellisenseStartedAt;
                        intellisenseOpenedAt  = intellisenseStartedAt;
                    }
                    else if (behindCaretChar == '>' || behindBehindCaretChar == ':' || behindBehindCaretChar == '>')
                    {
                        intellisenseStartedAt = caretIndex - 1;
                        intellisenseEndsAt    = intellisenseStartedAt;
                        intellisenseOpenedAt  = intellisenseStartedAt;
                    }
                    else
                    {
                        await
                        Dispatcher.UIThread.InvokeTaskAsync(
                            () =>
                        {
                            if (caretIndex > 1)
                            {
                                intellisenseOpenedAt = caretIndex - 1;

                                intellisenseStartedAt = TextUtilities.GetNextCaretPosition(editor.TextDocument, caretIndex,
                                                                                           TextUtilities.LogicalDirection.Backward, TextUtilities.CaretPositioningMode.WordStart);
                            }
                            else
                            {
                                intellisenseOpenedAt  = 1;
                                intellisenseStartedAt = 1;
                            }

                            behindStartChar = editor.TextDocument.GetCharAt(intellisenseStartedAt - 1);

                            if ((behindStartChar.IsWhiteSpace() || !behindStartChar.IsSymbolChar()) && (caretChar.IsWhiteSpace() || !caretChar.IsSymbolChar()))
                            {
                                intellisenseEndsAt = intellisenseStartedAt;
                            }
                            else
                            {
                                intellisenseEndsAt = TextUtilities.GetNextCaretPosition(editor.TextDocument, caretIndex,
                                                                                        TextUtilities.LogicalDirection.Forward, TextUtilities.CaretPositioningMode.WordBorder) - 1;
                            }
                        });
                    }

                    if (IsIntellisenseResetKey(e))
                    {
                        intellisenseStartedAt++;
                        intellisenseOpenedAt++;
                    }

                    await Dispatcher.UIThread.InvokeTaskAsync(() =>
                    {
                        currentFilter = editor.TextDocument.GetText(intellisenseStartedAt, caretIndex - intellisenseStartedAt);

                        caret = GetTextLocation(intellisenseStartedAt);
                    });

                    var codeCompletionResults = await intellisenseControl.DoCompletionRequestAsync(caret.Line, caret.Column);

                    unfilteredCompletions.Clear();

                    if (codeCompletionResults != null)
                    {
                        foreach (var result in codeCompletionResults.Completions)
                        {
                            if (result.Suggestion.ToLower().Contains(currentFilter.ToLower()))
                            {
                                CompletionDataViewModel currentCompletion = null;

                                currentCompletion = unfilteredCompletions.BinarySearch(c => c.Title, result.Suggestion);

                                if (currentCompletion == null)
                                {
                                    unfilteredCompletions.Add(CompletionDataViewModel.Create(result));
                                }
                                else
                                {
                                    currentCompletion.Overloads++;
                                }
                            }
                        }
                    }

                    filteredResults = unfilteredCompletions;
                }
                else
                {
                    await Dispatcher.UIThread.InvokeTaskAsync(
                        () =>
                    {
                        if (intellisenseStartedAt != -1 && caretIndex > intellisenseStartedAt)
                        {
                            currentFilter = editor.TextDocument.GetText(intellisenseStartedAt, caretIndex - intellisenseStartedAt);
                        }
                        else
                        {
                            currentFilter = string.Empty;
                        }
                    });

                    filteredResults = unfilteredCompletions.Where(c => c.Title.ToLower().Contains(currentFilter.ToLower()));
                }

                CompletionDataViewModel suggestion = null;

                if (currentFilter != string.Empty)
                {
                    IEnumerable <CompletionDataViewModel> newSelectedCompletions = null;

                    newSelectedCompletions = filteredResults.Where(s => s.Title.StartsWith(currentFilter));
                    // try find exact match case sensitive

                    if (newSelectedCompletions.Count() == 0)
                    {
                        newSelectedCompletions = filteredResults.Where(s => s.Title.ToLower().StartsWith(currentFilter.ToLower()));
                        // try find non-case sensitve match
                    }

                    if (newSelectedCompletions.Count() == 0)
                    {
                        suggestion = noSelectedCompletion;
                    }
                    else
                    {
                        var newSelectedCompletion = newSelectedCompletions.FirstOrDefault();

                        suggestion = newSelectedCompletion;
                    }
                }
                else
                {
                    suggestion = noSelectedCompletion;
                }

                if (filteredResults?.Count() > 0)
                {
                    if (filteredResults?.Count() == 1 && filteredResults.First().Title == currentFilter)
                    {
                        await Dispatcher.UIThread.InvokeTaskAsync(() => { Close(); });
                    }
                    else
                    {
                        var list = filteredResults.ToList();

                        await Dispatcher.UIThread.InvokeTaskAsync(() =>
                        {
                            intellisenseControl.IsVisible = true;
                        });

                        await Dispatcher.UIThread.InvokeTaskAsync(() =>
                        {
                            intellisenseControl.CompletionData = list;

                            intellisenseControl.SelectedCompletion = null;
                            intellisenseControl.SelectedCompletion = suggestion;
                        });
                    }
                }
                else
                {
                    await Dispatcher.UIThread.InvokeTaskAsync(() => { Close(); });
                }
            }
            else if (IsAllowedNonFilterModificationKey(e))
            {
                // do nothing
            }
            else
            {
                if (intellisenseControl.IsVisible && IsCompletionKey(e))
                {
                    e.Handled = true;
                }

                await Dispatcher.UIThread.InvokeTaskAsync(() => { Close(); });
            }
        }
Пример #7
0
        private bool UpdateFilter(int caretIndex, bool allowVisiblityChanges = true)
        {
            bool result = false;

            if (!_requestingData)
            {
                if (_shell.DebugMode)
                {
                    _console.WriteLine("Filtering");
                }

                var wordStart = DocumentUtilities.FindPrevSymbolNameStart(editor.Document, caretIndex);

                if (wordStart >= 0)
                {
                    result        = true;
                    currentFilter = editor.Document.GetText(wordStart, caretIndex - wordStart).Replace(".", string.Empty).Replace("->", string.Empty).Replace("::", string.Empty);

                    if (currentFilter.Any(s => char.IsWhiteSpace(s)))
                    {
                        currentFilter = "";
                    }
                }
                else
                {
                    currentFilter = string.Empty;
                }

                if (_shell.DebugMode)
                {
                    _console.WriteLine($"Filter: {currentFilter}");
                }

                CompletionDataViewModel suggestion = null;

                var filteredResults = unfilteredCompletions as IEnumerable <CompletionDataViewModel>;

                if (currentFilter != string.Empty)
                {
                    filteredResults = unfilteredCompletions.Where(c => c != null && c.Title.ToLower().Contains(currentFilter.ToLower()));

                    IEnumerable <CompletionDataViewModel> newSelectedCompletions = null;

                    // try find exact match case sensitive
                    newSelectedCompletions = filteredResults.Where(s => s.Title.StartsWith(currentFilter));

                    if (newSelectedCompletions.Count() == 0)
                    {
                        newSelectedCompletions = filteredResults.Where(s => s.Title.ToLower().StartsWith(currentFilter.ToLower()));
                        // try find non-case sensitve match
                    }

                    if (newSelectedCompletions.Count() == 0)
                    {
                        suggestion = null;
                    }
                    else
                    {
                        var newSelectedCompletion = newSelectedCompletions.FirstOrDefault();

                        suggestion = newSelectedCompletion;
                    }
                }
                else
                {
                    suggestion = recommendedCompletion;

                    if (suggestion != null)
                    {
                        _hidden = false;
                    }
                }

                if (filteredResults?.Count() > 0)
                {
                    if (filteredResults?.Count() == 1 && filteredResults.First().Title == currentFilter)
                    {
                        CloseIntellisense();
                    }
                    else
                    {
                        var list = filteredResults.ToList();

                        intellisenseControl.SelectedCompletion = null;
                        intellisenseControl.CompletionData     = list;

                        Dispatcher.UIThread.InvokeAsync(() =>
                        {
                            intellisenseControl.SelectedCompletion = suggestion;
                        });

                        if (allowVisiblityChanges)
                        {
                            _hidden = false;

                            if (!_requestingData && !_hidden)
                            {
                                intellisenseControl.IsVisible = true;
                            }
                        }
                    }
                }
                else
                {
                    intellisenseControl.SelectedCompletion = null;
                }
            }

            return(result);
        }