如何将一些缓存信息附加到 Eclipse 编辑器或资源?

发布于 2024-12-18 13:35:32 字数 364 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫瑟鸿黎 2024-12-25 13:35:32

您可以利用 Xtext 提供的 JVM 模型。只要您安装了 groovy 插件,就应该可以通过它使用它的类型和方法。

缓存:

资源上有一个缓存,如果其中有更改,该缓存会自动被驱逐。

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

缓存也可以被注入:

@Inject
private IResourceScopeCache cache

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
歌枕肩 2024-12-25 13:35:32

我不确定,但我认为您可以重用 org.eclipse.xtext.util.SimpleCache 对于这种情况。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文