How to turn off global scope in XText 2.9?

2019-07-28 03:06发布

问题:

someone knows how to turn off the global scope in XText 2.9? I want to turn off the global scope in order to only can access the elements of the files that I import. For example:

file1.mydsl:
element A(C){
   ;
}
subelement C{
   ;
}

file2.mydsl:
element B(C){
   ;
}

This should return an error in file2.mydsl because I haven't imported "file1.mydsl". I should add the line - import "file1.mydsl" - to avoid the error. How can I do that in Xtext 2.9? I have a working code that does what I want but the code uses Xtext 2.8 and doesn't work on 2.9 version.

回答1:

hi you can still switch to importURI based scoping

https://bugs.eclipse.org/bugs/show_bug.cgi?id=491110

fragment = org.eclipse.xtext.generator.adapter.FragmentAdapter { fragment = org.eclipse.xtext.generator.scoping.ImportURIScopingFragment {} }

or simply by adding the bindings manually

class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {

    override bindIGlobalScopeProvider() {
        importuriglobalscopeprovider
    }

    override configureIScopeProviderDelegate(Binder binder) {
        binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE))
            .to(SimpleLocalScopeProvider);

    }

}