Xtext example of a scoped object

前端 未结 2 1358
-上瘾入骨i
-上瘾入骨i 2021-02-06 05:04

I\'m looking for an example (in XText) of how to implement code completion on an user defined objects members. As far as I can see I need to use IScope, but how all this wires t

2条回答
  •  北恋
    北恋 (楼主)
    2021-02-06 05:52

    It highly depends on your grammar what you have to do to adopt scoping. Let us say you have a grammar like

    Model:
        statements+=Statement+
    ;
    
    Statement:
        Trait | VarDef | Call
    ;
    
    Trait:
        "trait" name=ID "{"
            ops+=Operation*
        "}"
    ;
    
    Operation:
        "def" name=ID "()" ":" type=[Trait]
    ;
    
    VarDef:
        "val" name=ID "=" "new" type=[Trait] "()"
    ;
    
    Call:
        var=[VarDef] "." op=[Operation] "()"
    ;
    

    then your scopeprovider would look like

    public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
    
        IScope scope_Call_op(Call call, EReference ref) {
            return Scopes.scopeFor(call.getVar().getType().getOps());
        }
    }    
    

    You can find a blog series on the topic here:

    https://web.archive.org/web/20130129085620/http://blogs.itemis.de/stundzig/archives/773

提交回复
热议问题