Visual Studio 关闭鼠标悬停时自动出现快速文档浮层的方法

作者在 2019-06-22 20:40:20 发布以下内容

就是这个烦人的图层,像打不跑的苍蝇

QQ截图20190619164332.png (上传于2019-06-22 20:40:20)
QQ截图20190619164332.png


我在上篇博客狠狠的吐槽了这个设计 https://blog.bccn.net/静夜思/66713 ,不解决掉这个问题终日寝食难安。


苍天有眼,今天让我搜到一个10年前的帖子 https://stackoverflow.com/questions/4130598/how-do-i-turn-off-code-tooltips-in-visual-studio-2010 10年前就有人受这个困扰(然而官僚化的微软始终听不到用户的声音),并且开发了一个扩展,当然这个扩展现在已经不能用了。好在给了我一个启发。


于是我开始搜vs的扩展,联机搜“tooltips”关键字的时候搜到一个叫“Tame Visual Studio Editor Tooltips”的扩展,看上去像是关于编辑器Tooltips的,仔细看了一下介绍,果然是解决这个问题的。点击download安装即可。扩展详细介绍: https://marketplace.visualstudio.com/items?itemName=KarlShifflettkdawg.TameVisualStudioEditorTooltipsAsync


然而我高兴的还是太早了。这个扩展只支持了C#语言,VB.NET根本不如作者的法眼。好在这个扩展是开源的,顺着扩展的介绍页面找到了他的github页面 https://github.com/Oceanware/Tame-Visual-Studio-Code-Editor-Tooltips (可怜目前为止只有2个star,1个fork,其中一个star是我点的,唯一的fork也是我拉了个分支,可见微软的技术在开源社区是何等的冷清),通过阅读 TameVisualStudioEditorToolTips/TameQuickInfo.cs 的代码发现没有对vb.net的支持,这是15、16、17行的代码:

    [ContentType("CSharp")]
    [ContentType("XAML")]
    [ContentType("XML")]


然后克隆这个项目,加上Basic、HTML、CSS、Jscript的支持

namespace TameVisualStudioEditorToolTips {

    using System.ComponentModel.Composition;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Windows.Input;
    using Microsoft.VisualStudio.Language.Intellisense;
    using Microsoft.VisualStudio.Shell;
    using Microsoft.VisualStudio.Text;
    using Microsoft.VisualStudio.Utilities;

    [Export(typeof(IAsyncQuickInfoSourceProvider))]
    [Name("Tame Quick Info")]
    [Order(Before = "Default Quick Info Presenter")]
    [ContentType("CSharp")]
    [ContentType("Basic")]
    [ContentType("XAML")]
    [ContentType("XML")]
    [ContentType("HTML")]
    [ContentType("CSS")]
    [ContentType("JScript")]
    internal class TameQuickInfo : IAsyncQuickInfoSourceProvider {

        public IAsyncQuickInfoSource TryCreateQuickInfoSource(ITextBuffer textBuffer) {
            return textBuffer.Properties.GetOrCreateSingletonProperty(() => new CancelingQuickInfoSource());
        }
    }

    internal class CancelingQuickInfoSource : IAsyncQuickInfoSource {

        public CancelingQuickInfoSource() {
        }

        public void Dispose() {
        }

        public async Task<QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) {
            var isKeyDown = false;
            ThreadHelper.JoinableTaskFactory.Run(async delegate {
                // now on the UI thread
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                isKeyDown = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) || Keyboard.IsKeyDown(Key.LeftCtrl)  || Keyboard.IsKeyDown(Key.RightCtrl);
            });

            // back on background thread
            if (!isKeyDown) {
                _ = session.DismissAsync();
            }
            return await System.Threading.Tasks.Task.FromResult<QuickInfoItem>(null);
        }
    }
}


在visual studio里编译,安装,最后大功告成!😁


下面是我编译的扩展,支持C#、VB.NET代码屏蔽弹出浮层,下载了直接安装即可:

Windows | 阅读 4468 次
文章评论,共0条
游客请输入验证码
浏览2791363次
文章归档