如何将一些缓存信息附加到 Eclipse 编辑器或资源?
我正在使用 Eclipse 的 Xtext 框架开发 DSL。
对于内容辅助/代码完成,我有一个昂贵的过程来生成字符串列表。
如何缓存该过程的结果?
长话短说:我的 DSL 与 Groovy 脚本交互。这些脚本提供了我在 DSL 中某些位置提供的方法。即使我使用正则表达式来解析脚本的方法,这也相当慢。所以我想缓存脚本分析的结果。
根据我的分析,分析代码是在验证期间(因此我并不总是有编辑器)以及用户打开 DSL 文件时调用的。
无法判断验证何时结束(代码位于私有方法中,Xtext 开发人员拒绝更改它)。但我认为这一定是为 Eclipse 编写编辑器/编译器时的常见问题。其他人如何解决这个问题? Eclipse框架中有缓存服务吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以利用 Xtext 提供的 JVM 模型。只要您安装了 groovy 插件,就应该可以通过它使用它的类型和方法。
缓存:
资源上有一个缓存,如果其中有更改,该缓存会自动被驱逐。
缓存也可以被注入:
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.
The cache can also be injected :
我不确定,但我认为您可以重用
org.eclipse.xtext.util.SimpleCache
对于这种情况。I'm not sure, but I think you can reuse
org.eclipse.xtext.util.SimpleCache
for such case.