예제 #1
0
        private async void TextAreaTextEntered(object sender, TextCompositionEventArgs e)
        {
            recommendationCancellation.Cancel();

            if (WorkspaceService == null || DocumentFile == null)
            {
                return;
            }

            recommendationCancellation = new CancellationTokenSource();
            var cancellationToken = recommendationCancellation.Token;

            try
            {
                await updateTextTask;   // Wait for a pending UpdateText before calling GetRecommendedSymbolsAsync.
                cancellationToken.ThrowIfCancellationRequested();

                if (completionWindow == null && (e.Text == "." || IsAllowedLanguageLetter(e.Text[0])))
                {
                    var position = CaretOffset;
                    var word     = GetWord(position);

                    var symbols = await WorkspaceService.GetRecommendedSymbolsAsync(DocumentFile, position, cancellationToken);

                    cancellationToken.ThrowIfCancellationRequested();
                    var symbolGroups = symbols.GroupBy(x => x.Name).ToArray();
                    if (symbolGroups.Any())
                    {
                        using (new PerformanceTrace("CompletionWindow.Show", DocumentFile))
                        {
                            completionWindow = new CompletionWindow(TextArea)
                            {
                                WindowStyle        = WindowStyle.None,
                                AllowsTransparency = true
                            };
                            completionWindow.MaxWidth  = completionWindow.Width = 340;
                            completionWindow.MaxHeight = completionWindow.Height = 206;
                            foreach (var symbolGroup in symbolGroups)
                            {
                                completionWindow.CompletionList.CompletionData.Add(new CodeCompletionData(symbolGroup.Key, symbolGroup.ToArray()));
                            }

                            if (IsAllowedLanguageLetter(e.Text[0]))
                            {
                                completionWindow.StartOffset = word.Item1;
                                completionWindow.CompletionList.SelectItem(word.Item2);
                            }
                            completionWindow.Show();
                            completionWindow.Closed += (s2, e2) => completionWindow = null;
                        }
                    }
                }
            }
            catch (OperationCanceledException)
            {
            }
        }