简体   繁体   English

项目中所有文件的Xtext交叉引用

[英]Xtext cross-reference across all files in project

I am making a very simple DSL with xtext. 我正在用xtext做一个非常简单的DSL。 A project will contain files that either define a message name, or reference to one. 项目将包含定义消息名称或引用消息名称的文件。 I have included a simplified example: 我提供了一个简化的示例:

Grammar: 语法:

Model:
    statements+=(MessageDefinition | MessageUsage)*;
MessageDefinition:
    '[MESSAGE_DEF]' name=ID;
MessageUsage:
    '[MESSAGE_USAGE]' usage=[MessageDefinition];

File1.ex: File1.ex:

[MESSAGE_DEF] EXAMPLE_1
[MESSAGE_DEF] EXAMPLE_2
[MESSAGE_USAGE] EXAMPLE_1

File2.ex: File2.ex:

[MESSAGE_USAGE] EXAMPLE_2

In this example the cross-reference from EXAMPLE_1 works such that "Open Declaration" on the usage takes me to the definition. 在此示例中,EXAMPLE_1的交叉引用的工作方式是使用法上的“打开声明”将我带到定义。 However, the cross-reference on EXAMPLE_2 does not work. 但是,EXAMPLE_2上的交叉引用无效。 I think the default scoping rules prevents different files from sharing references. 我认为默认作用域规则会阻止其他文件共享引用。

What do i need to add so that all the files in a project share the same global scope for cross-references? 我需要添加什么以便项目中的所有文件共享相同的全局引用范围?

Additional information: 附加信息:

  • The option "Build Automatically" is enabled in the runtime project. 在运行系统项目中启用了“自动构建”选项。
  • The .project file includes a buildCommand for xtextBuilder and a nature for xtextNature. .project文件包括用于xtextBuilder的buildCommand和用于xtextNature的自然。
  • I am only attempting to use the IDE cross-referencing functionality, there is no generation of code. 我仅尝试使用IDE交叉引用功能,没有代码生成。
  • All of the files in the runtime project exist in the same folder. 运行时项目中的所有文件都存在于同一文件夹中。

The project was created using "Xtext Project" in the standard wizard, I have only edited the grammar from the pre-generated code, everything else is as-per the defaults. 该项目是使用标准向导中的“ Xtext Project”创建的,我只从预生成的代码中编辑了语法,其他所有内容均与默认设置相同。 I thought I would need to add some custom scoping behaviour/rules to load all files into the global scope, but I am not sure how this is supposed to be done? 我以为我需要添加一些自定义作用域行为/规则来将所有文件加载到全局范围中,但是我不确定应该怎么做?

it will work fine with your grammar and scoping if you 如果您的语法和作用域很好,它将很好地工作

  1. have build automatically enabled in your runtime workspace 在运行时工作区中自动启用了构建
  2. the project you model in has xtext nature and xtext builder enabled (right-click -> configure -> ...) 您在其中建模的项目具有xtext性质和启用的xtext构建器(右键单击->配置-> ...)
  3. if it is a java project model files have to reside in a source folder or a package within the source folder 如果是Java项目模型,则文件必须驻留在源文件夹或源文件夹内的包中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM