2

I'm developing a DSL using Eclipse's Xtext framework.

For the content assist/code completion, I have an expensive process which generates me a list of strings.

How do I cache the result of that process?

Long story: My DSL interfaces with Groovy scripts. The scripts provide methods which I offer in certain places in my DSL. This is pretty slow, even when I use a regexp to parse the methods of the scripts. So I'd like to cache the results of the script analysis.

From my analysis, the analysis code is called during validation (so I don't always have an editor) and when the user opens a DSL file.

There is no way to tell when the validation is over (the code is in a private method and the Xtext developers refuse to change that). But I figure that this must be a common problem when writing editors/compilers for Eclipse. How do other people solve this problem? Is there some caching service in the Eclipse framework?

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820

2 Answers2

1

You could make use of the JVM model Xtext provides. As long as you have the groovy plugin installed, its types and methods should be available through it.

Caching:

On the resource there is a cache which is automatically evicted if there's a change in it.

((XtextResource)x.eResource()).getCache().get(myKey, x.eResource(), 
    new Provider<List<String>>(){
        public List<String> get() {
            return computeGroovyMethodNames();
        }
    })

The cache can also be injected :

@Inject
private IResourceScopeCache cache
Sven Efftinge
  • 3,065
  • 17
  • 17
0

I'm not sure, but I think you can reuse org.eclipse.xtext.util.SimpleCache for such case.

Eldar Abusalimov
  • 24,387
  • 4
  • 67
  • 71