【问题标题】:Auto Completion Visual Studio自动完成 Visual Studio
【发布时间】:2016-11-29 07:31:06
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案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;
                }
    

    编辑:

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

    【讨论】:

    • 嗨,这就是我现在所拥有的。但我正在尝试更改悬停/滚动到时弹出的文本。根据您的示例,#adapt-samelevel 突出显示,在右侧,它再次显示 #adapt-samelevel。我想将该文本编辑为更有帮助的内容。我该怎么做?
    • 正如 Jason Malinowski 所说,使用 Description 属性
    • 我不知道如何使 strList 值与描述一致。你能给我举个例子吗?谢谢!
    • 我已经编辑了reprly上的代码,请检查这一行 //please add custom text as you want m_compList.Add(new Completion(str, str, "Test", null, null) );
    • 嗨,是的,但我的一切都是“测试”,不是吗?就像#adapt-samelevel 和#abort 和#adapt 一样,都会被标记为测试吗?我尝试输入多个 m_compList.Add(new Completion(str, str, "Test", null, null)); m_compList.Add(new Completion(str, str, "Something", null, null));但它不起作用。请指教!谢谢。
    【解决方案2】:

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

    【讨论】:

    • 我没有在任何地方添加“#adapt-samelevel”描述。我按照指南,添加了我自己的完成变量,这就出现了。突出显示的部分。我真的很想编辑该部分以提供某种提示。
    • 您能给我举个例子,说明如何将“#adapt-samelevel”与自定义描述相一致吗?
    猜你喜欢
    • 1970-01-01
    • 2017-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-11
    • 1970-01-01
    • 1970-01-01
    • 2017-07-11
    相关资源
    最近更新 更多