在自己的扩展中使用 IDocumentNavigationService

Using IDocumentNavigationService in own extension

我们正在开发一个 Visual Studio 插件,它应该允许用户跳转到新创建的函数中的代码位置(当然使用 CodeAnalysis)。实际上我们只能使用 VisualStudioWorkspace.TryGoToDefinition 跳转到 Symbols。底层接口 IDocumentNavigationService 会非常有用,因为它提供了 TryNavigateToSpanTryNavigateToPosition 等方法,但接口是内部的,因此我们无法获取导航服务的实例。

是否有其他服务可以帮助我们?或者有人知道是否有计划制作 IDocumentNavigationService 界面 public?

如果您希望我们做到 public,也只需在 GitHub. In the mean time, adapting from this answer is probably the right thing to do, although in your case you can get the DTE2 interface by doing (DTE2)GetService(typeof(SDTE)) from your package. There's other approaches mentioned here 上提交错误即可。