【问题标题】:DLTK indexing and refreshing editorDLTK 索引和刷新编辑器
【发布时间】:2015-04-13 14:57:54
【问题描述】:

我为一种新语言创建了一个插件,并使用 DLTK 进行索引和搜索功能。

我正在使用 Eclipse Luna (PDE 3.10.1) 和 DLTK (5.0)

我的问题是: 如何在选项卡之间切换时手动重新索引文件并刷新编辑器?

因为现在发生的情况是,如果重新打开文件时重新索引文件并更新错误标记,但在切换时不会更新错误标记,因为在其他选项卡中更改了相关文件。

我尝试如下:它正在索引但不刷新编辑器。

我添加了一个 IPartListener2,在 partBroughtToTop() 方法中我有以下代码用于索引和刷新。

IModelElement model = EditorUtility.getEditorInputModelElement(partRef.getPage().getActiveEditor(), true);

if (model instanceof ISourceModule) {
    ProblemCollector prob = new ProblemCollector();
    SourceParserUtil.clearCache();
    // get cache entry
    final ISourceModuleInfo cacheEntry = ModelManager.getModelManager().getSourceModuleInfoCache().get((ISourceModule)model);
    ModuleDeclaration mod = (ModuleDeclaration)SourceParserUtil.parse((ISourceModule)model, prob);
    SourceParserUtil.putModuleToCache(cacheEntry, mod, prob);
    SourceParserUtil.enableCache();

    IEditorPart editor = partRef.getPage().getActiveEditor();
    IEditorInput input = editor.getEditorInput();
    try {
     ((ScriptEditor)editor).getDocumentProvider().resetDocument(input);
    }
    catch (CoreException e) {
    }
}

提前致谢。

【问题讨论】:

  • 有点不清楚你的代码在做什么。项目应该具有您的语言性质,并且其中的文件将在每次更改后自动编制索引。
  • @AlexPanchenko 我有一种语言,其中有不同类型的文件。例如,在 C++ 程序中,我们有 .cpp 和 .h 文件。如果我更改依赖 .h 文件中的变量,当我切换选项卡时,它不会反映在 cpp 文件中。但如果我重新打开 cpp 文件,它会反映更改。所以,当我在 Eclipse 中切换选项卡时,我想从代码中手动刷新。

标签: eclipse eclipse-plugin eclipse-rcp eclipse-pde dltk


【解决方案1】:

如果我理解正确,问题在于更改依赖项后重新验证文件。 1.与indexer无关(只是记录一个文件包含一些元素) 2.它与解析器(产生AST)无关。

它应该发生在构建器中。您可以通过实现 IBuildParticipant 或 IScriptBuilder 来尝试支持 DLTK。

【讨论】:

  • 感谢@Alex,您的回答有助于找到解决方案。我添加了 buildParticipant,这是插件的扩展。然后我添加了与 ParserBuildParticipant 相同的 IBuildParticipant。当我在选项卡之间切换时,我调用 ScriptBuilderUtil.build() 方法。它会调用 ParserBuildParticipant 的 build() 方法,然后我对文件进行强制解析。它会重新索引文件并正确更新问题标记。虽然它会稍微降低性能,因为索引会发生两次。 DLTK 索引的概念有点难理解,但现在可以正常工作了。
猜你喜欢
  • 2012-10-31
  • 1970-01-01
  • 1970-01-01
  • 2014-11-17
  • 2012-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多