代码之家  ›  专栏  ›  技术社区  ›  bharal OpherV

com.intellij.openapi.project.IndexNotReadyException文档

  •  -2
  • bharal OpherV  · 技术社区  · 6 年前

    我正在制作一个intellij插件。当我在应用程序中运行一些代码时,会收到此通知 selectionChanged 方法 FileEditorManagerListener .

    我不知道文档中提到了什么-所有对这个的引用都指向了一些android bug,但我不是在android上工作,这是一个实际的intellij插件。

    任何想法-我怀疑我不打算在应用程序索引时“运行”这段代码,但我不确定如何做到这一点。

    1 回复  |  直到 6 年前
        1
  •  -4
  •   bharal OpherV    6 年前

    答案很简单——当然,intellij团队似乎想制作他们的插件代码 太难了 理解。我不明白为什么人们不关心实际的文档。真是太遗憾了。

    @Override
    public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
       try {
          showItem(toolWindow.getComponent(), file);
       } catch (IndexNotReadyException ex) {
          DumbService.getInstance(project).runWhenSmart(() -> showItem(toolWindow.getComponent(), file) );
       }
    }
    

    诀窍是使用try/catch块,然后使用“DumbService”。这不是一个完整的解决方案,doco

    …但如果 编写文档的人不能费心去表达什么是检查,而编写代码的人也不能费心去编写不需要检查的代码

    我是说,核弹不会爆炸,对吧?