自动完成Visual Studio

时间:2016-11-29 07:31:07

标签: c# visual-studio autocomplete intellisense visual-studio-extensions

我重新创建了Walkthrough: Displaying Statement Completion 并设法让它运行起来。但是,我想知道是否可以添加自定义文本。

Highlighted

我似乎找不到它显示/调用突出显示的" #adcust-samelevel弹出窗口的地方。我想让它说一个小描述。

2 个答案:

答案 0 :(得分:1)

请在ICompletionSource.AugmentCompletionSession方法上添加自定义测试,如下所示:

 void ICompletionSource.AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets)
    {
        List<string> strList = new List<string>();
        strList.Add("addition");
        strList.Add("adaptation");
        strList.Add("subtraction");
        strList.Add("test");
        strList.Add("text");
        strList.Add("t~e#@xt");
        strList.Add("@text");
        strList.Add("@aaaaaa");
        strList.Add("~text");
        strList.Add("#adapt-samelevel");
        strList.Add("#abort");
        strList.Add("#adapt");
        strList.Add("#adapt-modified");
        m_compList = new List<Completion>();
        foreach (string str in strList)
           //please add custom texts as you want
            m_compList.Add(new Completion(str, str, "Test", null, null));

        completionSets.Add(new CompletionSet(
            "Tokens",    //the non-localized title of the tab
            "Tokens",    //the display title of the tab
            FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer),
                session),
            m_compList,
            null));
    }

它在Exec方法(类名TestCompletionCommandHandler)中使用字母和数字进行了约束。您可以修改约束。更改以下代码

if (!typedChar.Equals(char.MinValue) && char.IsLetterOrDigit(typedChar))
            {
                if (m_session == null || m_session.IsDismissed) // If there is no active session, bring up completion
                {
                    this.TriggerCompletion();
                    m_session.Filter();
                }
                else    //the completion session is already active, so just filter
                {
                    m_session.Filter();
                }
                handled = true;
            }

作为

if (!typedChar.Equals(char.MinValue))  //remove the constraint
            {
                if (m_session == null || m_session.IsDismissed) // If there is no active session, bring up completion
                {
                    this.TriggerCompletion();
                    m_session.Filter();
                }
                else    //the completion session is already active, so just filter
                {
                    m_session.Filter();
                }
                handled = true;
            }

enter image description here

enter image description here

编辑:

您可以使用Diction代替字符串,如下所示:

void ICompletionSource.AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets)
        {
            Dictionary<string, string> strList = new Dictionary<string, string>();
            strList.Add("#adapt-samelevel", "Test1");
            strList.Add("abort", "Test2");
            strList.Add("#adapt-modified", "Test3");
            m_compList = new List<Completion>();
            foreach (KeyValuePair<string, string> kvp in strList)
                m_compList.Add(new Completion(kvp.Key, kvp.Key, kvp.Value, null, null));

            completionSets.Add(new CompletionSet(
                "Tokens",    //the non-localized title of the tab
                "Tokens",    //the display title of the tab
                FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer),
                    session),
                m_compList,
                null));
        }

答案 1 :(得分:0)

这只是您正在创建和添加的补丁的Description property