public override async System.Threading.Tasks.Task <ICompletionDataList> HandleCodeCompletionAsync(CodeCompletionContext completionContext, CompletionTriggerInfo triggerInfo, System.Threading.CancellationToken token)
        {
            if (triggerInfo.CompletionTriggerReason == CompletionTriggerReason.CompletionCommand)
            {
                if (hiddenInfo != null && (isInCSharpContext || Tracker.Engine.CurrentState is RazorState) &&
                    !(Tracker.Engine.Nodes.Peek() is XElement))
                {
                    InitializeCodeCompletion();
                    return(await completionBuilder.HandlePopupCompletion(defaultEditor, defaultDocumentContext, hiddenInfo));
                }
            }
            char previousChar = defaultEditor.CaretOffset > 1 ? defaultEditor.GetCharAt(
                defaultEditor.CaretOffset - 2) : ' ';

            if (triggerInfo.CompletionTriggerReason != CompletionTriggerReason.CharTyped)
            {
                return(null);
            }
            // Don't show completion window when directive's name is being typed
            var directive = Tracker.Engine.Nodes.Peek() as RazorDirective;

            if (directive != null && !directive.FirstBracket.HasValue)
            {
                return(null);
            }
            var completionChar = triggerInfo.TriggerCharacter.Value;

            if (hiddenInfo != null && isInCSharpContext)
            {
                var list = (CompletionDataList)await completionBuilder.HandleCompletion(defaultEditor, defaultDocumentContext, completionContext,
                                                                                        hiddenInfo, completionChar, token);

                if (list != null)
                {
                    //filter out the C# templates, many of them are not valid
                    int oldCount = list.Count;
                    list = FilterCSharpTemplates(list);
                    int templates = list.Count - oldCount;

                    if (previousChar == '@')
                    {
                        RazorCompletion.AddAllRazorSymbols(list, razorDocument.PageInfo.HostKind);
                    }
                    if (templates > 0)
                    {
                        AddFilteredRazorTemplates(list, previousChar == '@', true);
                    }
                }
                return(list);
            }

            return(await base.HandleCodeCompletionAsync(completionContext, triggerInfo, token));
        }
        public override ICompletionDataList HandleCodeCompletion(CodeCompletionContext completionContext,
                                                                 char completionChar, ref int triggerWordLength)
        {
            if (!EnableCodeCompletion)
            {
                return(null);
            }

            char previousChar = defaultDocument.Editor.Caret.Offset > 1 ? defaultDocument.Editor.GetCharAt(
                defaultDocument.Editor.Caret.Offset - 2) : ' ';

            // Don't show completion widnow when directive's name is being typed
            var directive = Tracker.Engine.Nodes.Peek() as RazorDirective;

            if (directive != null && !directive.FirstBracket.HasValue)
            {
                return(null);
            }

            if (hiddenInfo != null && isInCSharpContext)
            {
                var list = completionBuilder.HandleCompletion(defaultDocument, completionContext, hiddenInfo,
                                                              completionChar, ref triggerWordLength);

                if (list != null)
                {
                    var templates = list.Select(c => c as CompletionData).Where(c => c != null &&
                                                                                (c.Icon.Name == "md-template" || c.Icon.Name == "md-template-surroundwith")).ToList();
                    foreach (var template in templates)
                    {
                        list.Remove(template);
                    }
                    var result = list as CompletionDataList;
                    if (previousChar == '@')
                    {
                        RazorCompletion.AddAllRazorSymbols(result);
                    }
                    if (templates.Count > 0)
                    {
                        MonoDevelop.Ide.CodeTemplates.CodeTemplateService.AddCompletionDataForMime("text/x-cshtml", result);
                    }
                }
                return(list);
            }

            return(base.HandleCodeCompletion(completionContext, completionChar, ref triggerWordLength));
        }
Beispiel #3
0
        public override ICompletionDataList HandleCodeCompletion(CodeCompletionContext completionContext,
                                                                 char completionChar, ref int triggerWordLength)
        {
            if (!EnableCodeCompletion)
            {
                return(null);
            }

            char previousChar = defaultDocument.Editor.Caret.Offset > 1 ? defaultDocument.Editor.GetCharAt(
                defaultDocument.Editor.Caret.Offset - 2) : ' ';

            // Don't show completion window when directive's name is being typed
            var directive = Tracker.Engine.Nodes.Peek() as RazorDirective;

            if (directive != null && !directive.FirstBracket.HasValue)
            {
                return(null);
            }

            if (hiddenInfo != null && isInCSharpContext)
            {
                var list = (CompletionDataList)completionBuilder.HandleCompletion(defaultDocument, completionContext,
                                                                                  hiddenInfo, completionChar, ref triggerWordLength);

                if (list != null)
                {
                    //filter out the C# templates, many of them are not valid
                    int oldCount = list.Count;
                    list = FilterCSharpTemplates(list);
                    int templates = list.Count - oldCount;

                    if (previousChar == '@')
                    {
                        RazorCompletion.AddAllRazorSymbols(list, razorDocument.PageInfo.HostKind);
                    }
                    if (templates > 0)
                    {
                        AddFilteredRazorTemplates(list, previousChar == '@', true);
                    }
                }
                return(list);
            }

            return(base.HandleCodeCompletion(completionContext, completionChar, ref triggerWordLength));
        }