当打开不属于项目的 cs 文件时,有什么方法可以使 Intellisense 工作?
我们理想地需要的是,了解 Microsoft 如何处理 XAML 生成的代码(那些 *.g.cs 文件)。 如果您转到后面的 XAML 代码,即使 *.g.cs 文件不是项目的一部分,智能感知也会工作!
上下文:
在自定义 VS 包中,我们需要一些逻辑来在 VS IDE 中打开 CS 文件(而不是使其成为项目的一部分),以允许用户对其进行编辑。
我们将文档连接到正在运行的文档表,并使用 IVSRunningDocumentTable 接收“保存”、“关闭”等事件。 效果很好。
现在的问题是,当文档打开时,智能感知无法工作,原因很简单,打开的文档不是项目的一部分(遗憾的是,我们不能这样做,我们不能让它在代码后面) 。
What we ideally need is, to know how Microsoft handles XAML generated code (Those *.g.cs files). If you goto a XAML code behind, intellisense will work even if the *.g.cs file is not part of the project!!
Context:
In a custom VS package, we need to have some logic to open a CS file (with out making it a part of the project) in the VS IDE, to allow the user to edit it.
We are hooking up the document to the Running document table and receiving the events like Saving, Close and all, using IVSRunningDocumentTable. Works good.
Now the problem is, when the document is opened, Intellisense can't work, for the simple reason that the opened document is not part of the project (sadly, we can't do that, we can't make it code behind).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
智能感知由标识符和类型的内存缓存驱动。 这些类型根据您所在的项目以及该项目具有的引用进行缓存。 如果您正在编辑的代码文件不是项目的一部分,Visual Studio 将必须加载每个可能的程序集并为整个 .NET 框架中的每种类型创建智能感知数据,因为它无法知道您的代码文件是否存在需要它。
我猜想 Visual Studio可以根据文件的内容加载智能感知,但这不是它当前的工作方式。
Intellisense is driven by a memory cache of identifiers and types. These types are cached based on the project you are in and the references that project has. If the code file you are editing is not part of a project, Visual Studio would have to load every possible assembly and create intellisense data for each type in the entire .NET framework because it would have no way of knowing whether or not your code file required it.
I guess Visual Studio could load intellisense based on the content of the file but that is not the way it currently works.
Whole Tomato 的 Visual Assist X 是我多年来一直使用的 VS 的一个插件。 当您打开它时,它会给您智能感知和更多功能。
Visual Assist X by Whole Tomato is an addin to VS I've been using for many years. It will give you Intellisense and more when you open it.