自定义Intellisense扩展 [英] Custom Intellisense Extension

查看:87
本文介绍了自定义Intellisense扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Visual Studio中为intellisense编写附加内容.

是否有可能进行扩展,根据我的研究,我还没有发现有关智能感知扩展的任何示例或文档.

我如何获得智能提示来显示简单的HelloWorld消息,如下所示(在运行时将hello world添加到String的智能提示中):

解决方案

因此,在Visual Studio 2010和更高版本中,要使用的可扩展性API位于Microsoft.VisualStudio.Languages.IntelliSense命名空间下.在较高的级别上,您要MEF导出ICompletionSourceProvider,它将提供您所需的项目. 此处AugmentCompletionSource中现有的完成集之一,但我不知道这样是否可行.无论如何,绝对是不支持的.

第二,很难知道何时何地推荐事物.在您的示例中,您说的是"string的IntelliSense".可悲的是,VS中没有任何API(当前)可以让您知道点之前的内容.您可以执行一些简单的试探法,也可以尝试实现一些适用于您的场景的Good Enough™解析器,但是您现在必须接受,因为您将不会获得完美的结果.

Roslyn 项目旨在解决第二个问题,因此您可能会发现进一步探索它很有用.由于我们希望很多人希望扩展完成范围,因此我们也在考虑提供其他可扩展性API,这样就不必从头开始编写ICompletionSourceProvider了,但是此类API不在当前的CTP中.

[免责声明:我是Roslyn团队的成员,致力于智能感知.]

I am wanting to write an addition to intellisense in Visual Studio.

Is it possible to extend at all, from my research I haven't found any samples or documentation on intellisense extensions.

How can I get intellisense to show a simple HelloWorld message like the following (where hello world is added at run time to the intellisense for String):

解决方案

So in Visual Studio 2010 and later, the extensibility APIs you want to at are under the Microsoft.VisualStudio.Languages.IntelliSense namespace. At a high level, you want to MEF export a ICompletionSourceProvider which will provide the items you need. There are two good blog posts here and here that demonstrate the basic technique.

There are two problems that you'll run into if you wanted to make your screenshot be a reality. (This is why I asked for the scenario, as my advice here would change.) First, this method doesn't legally let you append to an existing completion set, but rather provide a new one. In the UI this appears as two tabs, like the Common/All tabs in the Visual Basic editor. This is a limitation of the current API. You could try to modify one of the existing completion sets in your AugmentCompletionSource but I have no idea if that'd work. It's definitely unsupported, in any case.

Second, it's really hard to know when and where to recommend things. In your example, you said "the IntelliSense for string". Sadly, there aren't any APIs (currently) in VS that let you know what the thing before the dot is. You could do some simple heuristics or try implementing some parser that is Good Enough™ for your scenario, but you'll have to accept for now that you won't have perfect results.

The Roslyn project aims to fix the second issue, so you may find it useful to explore a bit further. Since we expect that lots of people will want to extend completion, we're also thinking about offering other extensibility APIs so you don't have to roll a ICompletionSourceProvider from scratch, but such APIs are not in the current CTP.

[Disclaimer: I'm a member of the Roslyn team who works on IntelliSense.]

这篇关于自定义Intellisense扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆