Locate the folder including a file

Answered

I am writing a plugin to support a new JavaScript framework. To do so I would like to figure out if the project is using the framekwork.

Structure

workspace
  apps
      MyApp
          view
               mySubViewFolder // <= right-click here
                   View.js
          framework-project.json // <= check
  node_modules
      @framework-folder // <= check

 

 

Let's say someone right-clicks on the mySubViewFolder. I would have to check if there is a @framework-folder and a framework-project.json as well as if I am inside the view folder.

 

Currently I am iterrating up the path to see if inside any folder there are any of these files.
But I had hoped that by indexing there is a faster way.

 

If not, is there any way to keep the results of the paths?

Any ideas?

1
3 comments

Hi Kurt,
Please check com.intellij.psi.search.FilenameIndex for the items that can be located in unknown places.
For determining if the clicked file is in the “view” directory, I suggest checking its parents.

0

Hi Karol,
I would very much enjoy an example, because I am a total newbie to Plugin Development and to Java.

It's getting better, but for now a part of a single line of code, is not really helpful right now.

Thanks a lot for taking the time.

0

Hi Kurt,

In this case, I suggest investing some time in learning Java (or Kotlin) as it is a requirement for developing plugins.

I think it should be easy to find the method you need in the FilenameIndex class (getVirtualFilesByName() seems like the one you need):
https://github.com/JetBrains/intellij-community/blob/master/platform/indexing-api/src/com/intellij/psi/search/FilenameIndex.java#L75

I also recommend getting familiar with the Explore the API topic, which teaches how to find example implementations.​

0

Please sign in to leave a comment.