Problems with FileEditorProvider implemetation

Answered

Hello!

I have a class, that implements the FileEditorProvider and DumbAware interfaces.
For some reason, method accept() of FileEditorProvider interface is requested for infinite times, when the plugin user opens the file, which must be handled by this editor.

Can the trouble spot be in Cyrillic file name?
Thank you.

14 comments
Comment actions Permalink

Please show snippet of your accept() method

0
Comment actions Permalink
@Override
public boolean accept(@NotNull Project project, @NotNull VirtualFile virtualFile) {
String fileName = virtualFile.getName();
if (fileName.equals(getProperties().getString("property1"))
|| fileName.equals(getProperties().getString("property2"))
|| fileName.equals(getProperties().getString("property3"))
|| fileName.equals("property4") || fileName.equals("property5")) {
return true;
} else if (fileName.contains(getProperties().getString("property6"))) {
boolean isConnected = CLIENT.testConnection();
if (!isConnected) {
return false;
}

boolean isHtmlDisabled = false;
try {
isHtmlDisabled = Boolean.valueOf(PluginUtil.getUserPropertyFromProjectByKey(Configuration.getProperties().getString("property7"), project));
} catch (Exception e) {
logger.error(getLogMessages().getString("log.property8"), e.getMessage());
}

return !isHtmlDisabled;
}
return false;
}

0
Comment actions Permalink

Problem occurs only with property6 file name. 

0
Comment actions Permalink

Please investigate then

 CLIENT.testConnection();

and

PluginUtil.getUserPropertyFromProjectByKey(Configuration.getProperties().getString("property7"), project)

 

0
Comment actions Permalink

The return value of

 CLIENT.testConnection();

i logged with custom build. In that case it was always true.

PluginUtil.getUserPropertyFromProjectByKey(Configuration.getProperties().getString("property7"), project)

can not occur problems, because its wrapped with try-catch block. 

0
Comment actions Permalink

Could you please clarify

method accept() of FileEditorProvider interface is requested for infinite times

Do you mean you get StackOverflowError? Does problem still occur when removing DumbAware?

0
Comment actions Permalink

No.

As i understand, for each project file Intellij IDEA call accept() method of my implementation of FileEditorProvider. If accept() return true, this implementation will be used to handle file. 

So there are couple of cases (I don't know them exactly), when Intellij IDEA call accept(), get "true" as result value and then call accept() method again. And do it for an infinite number of times.

0
Comment actions Permalink

Please show stacktraces where you think this is a problem. Is this a performance problem for your implementation?

0
Comment actions Permalink

There are no stacktraces problem, because problem occurs immediately after file selection in project file tree. And accept() method is only one method was called.

Yes, it is problem for me, because content of this file i get from server, that has some response ping. When user select file, he get something like infinite indexation: 

0
Comment actions Permalink

I did not try to remove DumbAware interface. Can problem be occured by it?

0
Comment actions Permalink

I doubt removing DumbAware would help in your case.

com.intellij.openapi.fileEditor.FileEditorProvider#accept is expected to be fast and return immediately. Unfortunately there is no other API that would allow for use-cases like yours.

Please try to cache results in some way locally or persist status of file locally via com.intellij.openapi.vfs.newvfs.FileAttribute

0
Comment actions Permalink

So, you mean, that regular accept() method calling is provided by open API and it is normal work?
Thank you any way!

0
Comment actions Permalink

Yes, accept() is called (mostly) from com.intellij.openapi.fileEditor.impl.FileEditorProviderManagerImpl#getProviders.

I've updated the Javadoc of accept-method to clarify requirement.

0

Please sign in to leave a comment.