简体   繁体   中英

Xtext cross-reference across all files in project

I am making a very simple DSL with xtext. 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:

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

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. However, the cross-reference on EXAMPLE_2 does not work. 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.
  • I am only attempting to use the IDE cross-referencing functionality, there is no generation of code.
  • 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. 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 -> ...)
  3. if it is a java project model files have to reside in a source folder or a package within the source folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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