自动完成Visual Studio

问题描述 投票:0回答:2

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

Highlighted

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

c# visual-studio autocomplete intellisense visual-studio-extensions
2个回答
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));
        }

0
投票

这只是你正在创建和添加的完成的Description property

© www.soinside.com 2019 - 2024. All rights reserved.