首页 > 解决方案 > Xtext DSL 插件只为文件的第一行提供关键字建议

问题描述

我一直在使用 Xtext 开发 DSL 作为 Eclipse 插件,到目前为止,我能够达到运行时 Eclipse 应用程序在按下 Ctrl+空格时提供建议列表的地步。但是,建议仅针对文件的第一行显示。之后,无论我按了多少次 Ctrl+空格,建议都不会出现。下面是我的 Xtext 语法:

Domainmodel:
    (elements+=MainElement)
;

MainElement:
    ProjectionName | ProjectionComponent | LayerSpecification |
    Description | Capability | Category | ServiceGroup |
    IncludeFragment | {MainElement} Override | {MainElement} Overtake
;

ProjectionName:
    'projection' modelName=ID ';'
;

ProjectionComponent:
    'component' componentName=ID ';'
;

LayerSpecification:
    'layer' layerName=ID ';'
;

Description:
    'description' string=STRING ';'
;

Capability:
    'capability' type=('Online' | 'Offline') ';'
;

Category:
    'category' type=('Integration' | 'ExternalB2B' | 'Users') ';'
;

ServiceGroup:
    'servicegroup' type=('Mobility' | 'Reporting') ';'
;

IncludeFragment:
    ('@Dynamic_Component_Dependency' componentName=ID) 'include' 'fragment' fragmentToIncludeName=ID ';'
;

Override:
    '@Override'
;

Overtake:
    '@Overtake'
;

我还尝试了另一个没有此问题的更简单的示例(如下所述):-

Domainmodel:    (elements+=MainElement)* ;

MainElement:    FileName | Type  ;

Type:   Component | Layer | Description | Category | Entity | Comment ;

FileName:   'projection' name=ID ';' ;

Component:  'component' name=ID ';' ;

Layer:  'layer' name=ID ';' ;

Description:    'description' string=STRING ';' ;

List:   Users | Developers ;

Users:  'Users' ;

Developers:     'Developers' ;

Category:   'category' lists=List ';' ;

Entity:     'entityset' name=ID 'for' name2=ID ';' ;

Comment:    '----------' comment=ID '----------' ;

谁能帮助我理解为什么提到的问题发生在第一个代码而不是第二个代码上?

谢谢你!

标签: eclipseeclipse-plugindslxtext

解决方案


您的第二个语法在规则中使用零对多基数,Domainmodel: (elements+=MainElement)* ;而您的第一个语法似乎缺少*sign Domainmodel: (elements+=MainElement);

修复那个Domainmodel: (elements+=MainElement)*;会有所帮助。


推荐阅读