Project Errors Tab is not visible in Problems Pane

Answered

While developing an IntelliJ plugin, after I register a problem with the problem holder, the problems show up only for the currently open file and I have to open each file separately to view and fix the problems. In the problems pane, only the "Current File" tab shows up. ( The problems have already been registered with the problem holder with the visitor(PSIElementVisitor) running).

Is there something else that needs to be done for the problems for the entire project to show up in the problems pane at once ?

1
6 comments

Hi! I suppose that you have implemented `LocalInspectionTool`. In this case it works as expected: it works only with files currently opened in the editor and executed after each change of the file. You can run it on the whole project with an action `Run inspection by name`.

If you need to have some kind of on the fly analysis you will need to implement it yourself (it is unclear when to restart it). To report errors in the problems view you could use `com.intellij.analysis.problemsView.ProblemsCollector`.

At the same time we have `com.intellij.codeInspection.GlobalInspectionTool`, which can operate with global state (e.g. reference graph), but they don't work online as well.

0

Thanks Roman !
I have indeed implemented the LocalInspectionTool.

Would you please clarify more on the following :- 

1. For the "Run inspection by name" solution, I tried implementing it in a startup activity ( since I want it to run an inspection on whole project on startup) as show in the code below. It runs the scan as expected, but a popup dialog asking about the "Inspection Scope" of the inspection comes up. Is there a way to set "Whole Project" by default and skip this popup? Put more simply, I just want to run this inspection on startup for the whole project without any input from user. Also, I'm not sure what the last 3 arguments are supposed to be in runInspection method.

public class MyStartupActivity implements StartupActivity {
@Override
public void runActivity(@NotNull Project project) {
RunInspectionAction.runInspection(project,"my-project-scan",null,null,null);
}
}

2.  As for the GlobalInspectionTool solution, is there a corresponding method like visitFile from LocalInspectionTooł in this to perform similar operations ? Would be great if you elaborate more on this solution as well.

0

Could you please describe what you want to achieve?

Suggested solution works exactly as if the action was invoked by user: all problems which existed at that time would be found, no new problems would be added, outdated problems won't be removed (they would be invalidated if psi is deleted but generally they would be there forever). If it's what you want, then it's a solution. 

1. if you want to run inspection on the whole project, leave nulls as you have now. If you want some subset, then it's possible to configure files or elements in the parameters. It's not the api, sorry for that

2. From the described execution plan, global inspections would give exactly the same user experience. So it would be better to have your use case first 

Thanks,

Anna

0

Anna Kozlova

I already have a list of line numbers on which the problems are using an external utility.
All I want to achieve is that given the line number, I want to add problems for the files of my project (and not just the current file) so that I can provide quickfixes.
LocalInspectionTool is working perfectly for currently open file. But I want this to work such that problems for all files in the project are listed at one place.

 

And coming to your first point, on running the inspection from my startup activity, I get a popup dialog like this asking me the inspection scope: 

Is there a way to bypass it and directly start the inspection? I want whole project inspection scope by default.

Thank You !

0

To bypass the dialog, just call directly `com.intellij.codeInspection.actions.RunInspectionIntention#rerunInspection`. You would need `new AnalysisScope(project)` and

final InspectionProfile currentProfile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
final InspectionToolWrapper<?, ?> toolWrapper = currentProfile.getInspectionTool(shortName, project);

If I miss something, please refer to the implementation of the 

RunInspectionAction.runInspection(project,"my-project-scan",null,null,null);

it's all written there

Anna

0

It worked !
Thanks a lot Anna Kozlova !

0

Please sign in to leave a comment.