c# - Visual Studio 可扩展性 - 自定义语言文本编辑器设置

标签 c# visual-studio-2013 dsl vs-extensibility

我正在尝试在 Visual Studio 中开发一种语言服务,到目前为止,我已经能够为高亮显示和跨度实现基本的标记器:

enter image description here

但是,我想更进一步,在“文本编辑器”下添加我自己的部分,以便我可以维护选项卡设置,以及语言的类似设置(如下所示): enter image description here

我发现很难在线找到有关 Visual Studio 可扩展性的资源,因为您可以做很多事情,但通常很难知道从哪里开始。我也对自定义项目/项目服务感兴趣,但在查找示例时遇到类似问题。

我可能已经很接近了(由于自定义标记器),我只是不知道用什么来装饰导出的类型,或者我有很多基础工作要做。方向表示赞赏。

最佳答案

我找到了这个 blog post它有很多 Visual Studio 扩展项目示例。其中有一个项目叫Options Page – VS 2013。我想这就是您要找的:

Option page

对于您的具体情况,您应该调整类中的以下属性(取自示例)OptionsPagePackage.cs。特别是这些属性:

将“类别”作为第二个传递参数(对应于“工具”菜单中的主要类别)。

[ProvideOptionPageAttribute(typeof(OptionsPageGeneral),"Text Editor","General", 100, 101, true, new string[] { "Change sample general options (C#)" })] 
    [ProvideProfileAttribute(typeof(OptionsPageGeneral), "Text Editor", "General Options", 100, 101, true, DescriptionResourceID = 100)] 
    [ProvideOptionPageAttribute(typeof(OptionsPageCustom), "Text Editor", "Custom", 100, 102, true, new string[] { "Change sample custom options (C#)" })] 
    [InstalledProductRegistration("Text Editor", "My Options Page (C#) Sample", "1.0")] 
    [Guid(GuidStrings.GuidPackage)] 
    public class OptionsPagePackageCS : Package 
    { 
    .....
    }

DescriptionResourceID(100,101,102 等)在 xml 文件 VsPackage.resx 中定义,vsix 安装程序将使用它在工具菜单中插入标签:

<data name="100" xml:space="preserve">
    <value>My Managed Options (C#)</value>
    <comment>Options category</comment>
  </data>
  <data name="101" xml:space="preserve">
    <value>My Options</value>
    <comment>General page</comment>
  </data>
  <data name="102" xml:space="preserve">
    <value>Custom</value>
    <comment>Custom page</comment>
  </data>

这是我的尝试:

enter image description here

请小心,因为使用现有类别会覆盖现有类别。正如您在图片中看到的,没有所有其他语言的选项。

编辑:

正如 Alexander 指出的那样,为了避免覆盖现有配置(如果想将他的类别添加到“工具”菜单中的现有类别),必须将反斜杠添加到所提到的属性中的类别参数多于。例如:

[ProvideOptionPageAttribute(typeof(OptionsPageGeneral),"Text Editor","General", 100, 101, true, new string[] { "Change sample general options (C#)" })]

变成:

 [ProvideOptionPageAttribute(typeof(OptionsPageGeneral),"Text Editor\\MyOptionPage","General", 100, 101, true, new string[] { "Change sample general options (C#)" })]

在这种情况下,MyOptionPage 将成为文本编辑器的子项,并且不会覆盖现有配置。

希望对您有所帮助。

关于c# - Visual Studio 可扩展性 - 自定义语言文本编辑器设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29045671/

相关文章:

c# - Infragistics UltraGrid : How to force a CellUpdate event after user selects from drop down

c# - 存储在内存中的int和对象一样吗?

c# - Visual Studio 2013 错误 : IntelliSense not listing internal types of a friend assembly

asp.net - Visual Studio 发布配置文件 - 为什么不在源代码管理中进行跟踪?

c# - 系统UriFormatException : Invalid URI : The URI is Empty

c# - 来自字符串的动态 if 条件

c# - 为什么多语言解决方案不起作用?

ruby - 哪里可以学习 ruby​​ DSL?

java - 图形数据流组合框架

c# - 是否有基于 .NET 的 CSS 抽象库?