public virtual CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch, IProjectContent projectContent)
        {
            IInsightWindow insightWindow = null;

            switch (ch)
            {
            case '(':
                insightWindow = editor.ShowInsightWindow(new MethodInsightProvider(projectContent).ProvideInsight(editor));
                if (insightWindow != null && insightHandler != null)
                {
                    insightHandler.InitializeOpenedInsightWindow(editor, insightWindow);
                    insightHandler.HighlightParameter(insightWindow, 0);
                }
                return(CodeCompletionKeyPressResult.Completed);

                break;

            case '[':
                insightWindow = editor.ShowInsightWindow(new IndexerInsightProvider(projectContent).ProvideInsight(editor));
                if (insightWindow != null && insightHandler != null)
                {
                    insightHandler.InitializeOpenedInsightWindow(editor, insightWindow);
                }
                return(CodeCompletionKeyPressResult.Completed);

                break;

            case '<':
                ShowCompletion(new CommentCompletionItemProvider(), editor, projectContent);
                return(CodeCompletionKeyPressResult.Completed);

                break;

            case '.':
                ShowCompletion(new DotCodeCompletionItemProvider(projectContent), editor, projectContent);
                return(CodeCompletionKeyPressResult.Completed);

                break;

            case ' ':
                string word = editor.GetWordBeforeCaret();
                if (!String.IsNullOrEmpty(word))
                {
                    if (HandleKeyword(editor, word))
                    {
                        return(CodeCompletionKeyPressResult.Completed);
                    }
                }
                break;
            }
            return(CodeCompletionKeyPressResult.None);
        }
        public Tuple<bool, CodeCompletionKeyPressResult> TryComplete(ITextEditor editor, char ch, IInsightWindowHandler insightWindowHandler)
        {
            int cursor_offset = editor.Caret.Offset;
            if(char.IsLetterOrDigit(ch) && CodeCompletionOptions.InsightEnabled){
                var insight_window = editor.ShowInsightWindow(new []{ProvideInsight(editor)});
                if(insight_window != null && insightWindowHandler != null){
                    insightWindowHandler.InitializeOpenedInsightWindow(editor, insight_window);
                    insightWindowHandler.HighlightParameter(insight_window, 0);
                }
                return Tuple.Create(true, CodeCompletionKeyPressResult.Completed);
            }

            return Tuple.Create(false, CodeCompletionKeyPressResult.None);
        }
        public Tuple<bool, CodeCompletionKeyPressResult> TryComplete(ITextEditor editor, char ch, IInsightWindowHandler insightWindowHandler)
        {
            int cursor_offset = editor.Caret.Offset;
            if(ch == '['){
                var line = editor.Document.GetLineForOffset(cursor_offset);
                current_context_type = line.Text.Trim();
                var provider = new UserDefinedNameCompletionItemProvider(current_context_type);
                var list = provider.Provide(editor);
                if(list != null){
                    editor.ShowCompletionWindow(list);
                    return Tuple.Create(true, CodeCompletionKeyPressResult.Completed);
                }else{
                    return Tuple.Create(false, CodeCompletionKeyPressResult.None);
                }
            }else if(ch == ',' && CodeCompletionOptions.InsightRefreshOnComma && CodeCompletionOptions.InsightEnabled){
                IInsightWindow insight_window;
                if(insightWindowHandler.InsightRefreshOnComma(editor, ch, out insight_window))
                    return Tuple.Create(true, CodeCompletionKeyPressResult.Completed);
            }else if(ch == '.'){
                var line = editor.Document.GetLineForOffset(cursor_offset);
                var type_name = (current_context_type != null) ? current_context_type : line.Text.Trim();
                var semantic_infos = BVE5ResourceManager.RouteFileSemanticInfos;
                var result = CodeCompletionKeyPressResult.None;
                if(semantic_infos.ContainsKey(type_name)){
                    var type_semantic_info = semantic_infos[type_name];

                    var names = type_semantic_info
                        .Where(member => member.Key != "indexer")
                        .Select(m => m.Key)
                        .Distinct()
                        .ToList();
                    var descriptions = type_semantic_info
                        .Where(member => member.Key != "indexer")
                        .Select(m => BVE5ResourceManager.GetDocumentationString(m.Value[0].Doc))
                        .ToList();

                    var list = CompletionDataHelper.GenerateCompletionList(names, descriptions);
                    editor.ShowCompletionWindow(list);
                    result = CodeCompletionKeyPressResult.Completed;
                }

                if(current_context_type != null) current_context_type = null;

                return Tuple.Create(result != CodeCompletionKeyPressResult.None, result);
            }else if(ch == '(' && CodeCompletionOptions.InsightEnabled){
                var insight_window = editor.ShowInsightWindow(ProvideInsight(editor));
                if(insight_window != null && insightWindowHandler != null){
                    insightWindowHandler.InitializeOpenedInsightWindow(editor, insight_window);
                    insightWindowHandler.HighlightParameter(insight_window, 0);
                }
                return Tuple.Create(true, CodeCompletionKeyPressResult.Completed);
            }

            if(char.IsLetter(ch) && CodeCompletionOptions.CompleteWhenTyping){
                var builtin_type_names = BVE5ResourceManager.GetAllTypeNames();
                var list = CompletionDataHelper.GenerateCompletionList(builtin_type_names);
                list = AddTemplateCompletionItems(editor, list, ch);
                editor.ShowCompletionWindow(list);
                return Tuple.Create(true, CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion);
            }

            return Tuple.Create(false, CodeCompletionKeyPressResult.None);
        }
Ejemplo n.º 4
0
        public virtual CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
        {
            switch (ch)
            {
            case '(':
                if (enableMethodInsight && CodeCompletionOptions.InsightEnabled)
                {
                    IInsightWindow insightWindow = editor.ShowInsightWindow(new MethodInsightProvider().ProvideInsight(editor));
                    if (insightWindow != null && insightHandler != null)
                    {
                        insightHandler.InitializeOpenedInsightWindow(editor, insightWindow);
                        insightHandler.HighlightParameter(insightWindow, 0);
                    }
                    return(CodeCompletionKeyPressResult.Completed);
                }
                break;

            case '[':
                if (enableIndexerInsight && CodeCompletionOptions.InsightEnabled)
                {
                    IInsightWindow insightWindow = editor.ShowInsightWindow(new IndexerInsightProvider().ProvideInsight(editor));
                    if (insightWindow != null && insightHandler != null)
                    {
                        insightHandler.InitializeOpenedInsightWindow(editor, insightWindow);
                    }
                    return(CodeCompletionKeyPressResult.Completed);
                }
                break;

            case '<':
                if (enableXmlCommentCompletion)
                {
                    new CommentCompletionItemProvider().ShowCompletion(editor);
                    return(CodeCompletionKeyPressResult.Completed);
                }
                break;

            case '.':
                if (enableDotCompletion)
                {
                    new DotCodeCompletionItemProvider().ShowCompletion(editor);
                    return(CodeCompletionKeyPressResult.Completed);
                }
                break;

            case ' ':
                if (CodeCompletionOptions.KeywordCompletionEnabled)
                {
                    string word = editor.GetWordBeforeCaret();
                    if (!string.IsNullOrEmpty(word))
                    {
                        if (HandleKeyword(editor, word))
                        {
                            return(CodeCompletionKeyPressResult.Completed);
                        }
                    }
                }
                break;
            }
            return(CodeCompletionKeyPressResult.None);
        }