自动完成 Visual Studio

Auto Completion Visual Studio

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

我似乎找不到 shows/calls 突出显示的“#adapt-samelevel 弹出窗口的位置。我想让它说一个简短的描述。

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

请像这样在 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 方法(class 名称 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;
            }

编辑:

您可以使用 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));
        }