leonard chan leonard chan - 4 days ago 6
C# Question

Auto Completion Visual Studio

I've re-created the Walkthrough: Displaying Statement Completion and managed to get it running. However, I was wondering if it was possible to add in custom texts.

Highlighted

I can't seem to find the place where it shows/calls the highlighted "#adapt-samelevel popup. I would want to make it say a small description instead.

Answer

please add custom tests on ICompletionSource.AugmentCompletionSession method like this:

 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));
    }

It made a constraint in Exec method (class name TestCompletionCommandHandler) with letter and digit. You can modify the constraint. Change the following code

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;
            }

As

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

Edit:

You could use Diction instead string, like this:

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));
        }
Comments