0

I have created a plugin for a new language and used DLTK for indexing and searching feature.

I am using Eclipse Luna (PDE 3.10.1) and DLTK (5.0)

My question is: How can I manually re-index a file and refresh the editor when I switch between tabs?

Because what happens now is if a file is reopened that time it gets re-indexed and error markers are updated, but while switching it doesn't update the error markers as dependent files are changed in other tabs.

I tried as below: It's indexing but not refreshing the editor.

I added a IPartListener2 and in partBroughtToTop() method i have following code for indexing and refreshing.

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) {
    }
}

Thanks in advance.

  • It is a little bit not clear what your code is doing. A project should have your language nature and files in it will be indexed automatically after every change. – Alex Panchenko Apr 29 '15 at 09:29
  • @AlexPanchenko I have a language where there are different types of files. For example, in C++ program, we have .cpp and .h files. If i change a variable in the dependent .h file it doesn't reflect in the cpp file when I switch tab. But it reflects the changes if I re-open the cpp file. So, I want to do a manual refresh from code when I switch tab in Eclipse. – Saroj Padhy Apr 29 '15 at 12:13

1 Answers1

1

If I understand correctly, the issue is about re-validating files after changing dependencies. 1. It is not related to indexer (it just records that a file contains some elements) 2. It is not related to parser (which produces AST).

It should happen in a builder. You could try DLTK support for that by implementing IBuildParticipant or IScriptBuilder.

Alex Panchenko
  • 452
  • 2
  • 6
  • Thanks @Alex your answer was helpful finding the solution. I added buildParticipant, an extension to the plugin. And then I added IBuildParticipant same as ParserBuildParticipant. When I switch between tabs I call ScriptBuilderUtil.build() method. It would call the build() method of ParserBuildParticipant and there I do a forceful parsing of the file. And it re-index the file and update the problem markers correctly. Though it reduces performance a little bit, because the indexing happens twice. It's little hard to understand the concept of the indexing by DLTK, but it works fine now. – Saroj Padhy May 01 '15 at 15:12