Write an inspection for non-content root files

Hi,

I'd like to write a plugin that adds a file-level inspection for files outside my user's java content root. I wrote a very simple InspectionToolProvider and LocalInspectionTool that does what I want, but I notice that it's only triggered for files in my project's java content roots. The "click to configure highlighting in this file" cop in the status bar has his head turned away for exactly the files I'd like to trigger this in, and there appears to be no way to switch it on.

The purpose of this inspection is to make it easy for users to pull files into their content root, and so it only really makes sense for files that are not in the content root. Is there any way to do this?

Thanks,
Brian

3 comments
Comment actions Permalink

Hello Brian,

If a LocalInspectionTool doesn't do what you want, the solution is - unsurprisingly
- to write a GlobalInspectionTool. :) It lets you handle traversal by yourself
in the runInspection() method, so you can look at files outside content roots.

I'd like to write a plugin that adds a file-level inspection for files
outside my user's java content root. I wrote a very simple
InspectionToolProvider and LocalInspectionTool that does what I want,
but I notice that it's only triggered for files in my project's java
content roots. The "click to co

nfigure highlighting in this file" cop in the status bar has his head
turned away for exactly the files I'd like to trigger this in, and
there appears to be no way to switch it on.

The purpose of this inspection is to make it easy for users to pull
files into their content root, and so it only really makes sense for
files that are not in the content root. Is there any way to do this?


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Ah yeah -- I saw that, but this javadoc put me off:

"Global inspections work only in batch mode (when the "Analyze / Inspect Code" is invoked)"

That's not what I'm looking for: I don't want the user to have to manually invoke analysis in order to see this (since they probably never will). I want it to appear in the code editor automatically like other local inspections. My use case is when a user does Go To->Declaration on a class, and ends up in a file that's outside the content root, or in a source jar. In many cases, we know how to interact with our VCS to open a version of the file that's locally editable (and optionally add it to the content root), so I wanted to provide an assist to do this easily. It's a little hard to explain why this is so useful to us without going into a lot of detail about how our VCS works. But it would be very, very useful

I'll try it anyway, and see whether it's just that the documentation is out of date.

Failing that, I've been experimenting with the FileEditorManager's addTopComponent() API, which seems to allow me to do what I want by bypassing the inspections API entirely.

Thanks,
Brian

0
Comment actions Permalink

Hello Brian,

The documentation is correct in this case. setTopComponent() is indeed probably
the best solution for your problem.

Ah yeah -- I saw that, but this javadoc put me off:

"Global inspections work only in batch mode (when the "Analyze /
Inspect Code" is invoked)"

That's not what I'm looking for: I don't want the user to have to
manually invoke analysis in order to see this (since they probably
never will). I want it to appear in the code editor automatically like
other local inspections. My use case is when a user does Go
To->Declaration on a class, and ends
up in a file that's outside the content root, or in a source jar. In
many cases, we know how to interact with our VCS to open a version of
the file that's locally editable (and optionally add it to the content
root), so I wanted to provide an assist to do this easily. It's a
little hard to explain
why this is so useful to us without going into a lot of detail about
how our VCS works. But it would be very, very useful

I'll try it anyway, and see whether it's just that the documentation
is out of date.

Failing that, I've been experimenting with the FileEditorManager's
addTopComponent() API, which seems to allow me to do what I want by
bypassing the inspections API entirely.

Thanks,
Brian
---
Original message URL:
http://www.jetbrains.net/devnet/message/5242135#5242135

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.