在 GNAT GPS 插件中设置 project_attribute 中的默认项目列表

Setting a default list of items in project_attribute in a GNAT GPS Plugin

我正在开发自定义 GNAT GPS 插件(适用于 GPS 6.1.2)。

我的插件 XML 创建了一个项目属性 "example_list_of_files"。 这是一个字符串列表,对应于项目中 Ada 文件的名称。 我想将该列表中的条目默认为 "a.adb"、"b.adb"、"c.adb"。但是我一直找不到正确的语法。相反,我最终得到了所有值的单个字符串。

我想看看当你手动添加三个元素时会发生什么,如下图:

下面是这个例子的代码:

GPS.parse_xml('<?xml version="1.0" ?>' + """
    <my_plugin> 
      <project_attribute
        name="example_list_of_files"
        label="example_list_of_files"
        description="A description...."
        package="MyPackage"
        editor_page="MyPage"
        editor_section="Build"
        hide_in="wizard library_wizard"
        omit_if_default="false"
        list="true"
        base_name_only="true">

          <string type="file" filter="project" default="'a.adb','b.adb','c.adb' " />

      </project_attribute>  
    </my_plugin>""");

请注意具有项目属性 defaultstring 元素。它没有项目管理器中的条目列表,而是给了我一个条目,其中包含字符串“'a.adb'、'b.adb'、'c.adb'”。

有人有什么想法吗?我还尝试了多个字符串元素,添加方括号、大括号、方括号、space 分隔符、'array(' 前缀,但没有成功。

谢谢

马特

来自 GPS 用户指南:

The tag accepts the following attributes:

[...]

  • list (boolean, default false)

    If true, the project attribute contains a list of values, as opposed to a single value. An example is the list of source directories in standard projects.

在你的例子中:

<string type="file" filter="project" default="'a.adb','b.adb','c.adb' " />

这是一个单一的字符串值。相反,您应该指定一个字符串值列表,如下所示:

<string type="file" filter="project" default="a.adb" />
<string type="file" filter="project" default="b.adb" />
<string type="file" filter="project" default="c.adb" />

看来确实不支持。标准插件 projects.py 有几个列表属性,但它们都有一个默认值。我会在这里检查可以做哪些改进。

但是,您的方法一开始可能就是错误的。您设置的默认值仅涉及项目编辑器。这意味着如果用户使用默认项目(如 project default is end default)并且从未通过项目编辑器,那么您的属性 example_list_of_files 实际上将不存在(并且具有默认的空值)。所以看起来这实际上应该在您的插件中处理,当您查询属性的值时(例如通过 GPS.Project.get_attribute_as_list)。如果该函数 returns 是一个空列表,则使用 ("a.adb", "b.adb", "c.adb") 代替。这样,即使使用默认的、未经编辑的项目也能正常工作。