Locate the folder including a file

已回答

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

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

Karol Lewandowski Excuse me, but this is really awful reply and not helping at all. I'm currently stuck at same scenario and what you recommend is to learn Java/Kotlin. Hey, I've been using java for 5+ years and this issue has nothing to do with language skills. The problem is that API sucks. No to little documentation about API, and how should you handle it. No java docs in code, describing what method to use. I've spent last 5 days trying to decipher what is in API, then I used chatGPT and even tried to use somebody's else code to get hang of it. Still stuck.

Let's be more specific - I'm trying to find files in my projects (inside plugin) → so I use recommended FilenameIndex.getVirtuaLFilesByName(…) → instead of all files that should be there I get only one entry. In theory the entry contains the files, but also others. Now, does it mean I will always get directory parent? Or only in specific case? You see? Should I now dig through Intellij binaries to find out what I really get? I always took intellij as awesome tool, but with provided API, that is evolving and always missing documentation + examples, it horrendous to create something. I'm in ave for guys, who created something for others. I cannot imagine how it is even for developer. Or do they have better docs? Maybe Jetbrains should share them, cos we are paying a lot of money for tool. What's more, the plugin is providing more value to Jetbrain's product, but somehow you don't find relevant to improve it…
Rant over.

Tldr: Jetbrains should get better with documenting their API - it should be self-explanatory, without need to debug it and dig into code. Current state is awful.

0

Hi,

Thank you for your feedback.

Please understand that the number of support requests on all channels is quite high. We have to find the balance between getting into too much detail in each question and giving pointers and hoping that developers will be able to continue the work. If something is still unclear and developers show they put an effort into trying the hints, we are happy to help. If I know the full solution to a problem, I'm more than happy to share it 🙂

In this post, I assumed that Kurt had problems with following the code or finding examples. I didn't mean to be rude. Anyway, I believe they solved the issue with the pointers.

Let's be more specific - I'm trying to find files in my projects (inside plugin) → so I use recommended FilenameIndex.getVirtuaLFilesByName(…) → instead of all files that should be there I get only one entry. In theory the entry contains the files, but also others. Now, does it mean I will always get directory parent? Or only in specific case? You see? Should I now dig through Intellij binaries to find out what I really get?

I'm sorry, but the real answer is: if the documentation is not available for the API you are trying to use, or it is poor, and the behavior is unexpected, then yes, after verifying that there is no bug in your code, I advise you to go through the code (source code is available and should be attached to the plugin project if the Gradle approach is used) or even debug it to try to understand what's going on, if the code is unclear. Also, it is helpful to check the API usages in the platform code. In many cases, it turns out that the API works as expected, and the bug was in plugin code. API behavior can depend on your specific context. If it's still unclear or hard to understand, feel free to ask on the forum or Slack about an explanation. We will help.

Tldr: Jetbrains should get better with documenting their API - it should be self-explanatory, without need to debug it and dig into code. Current state is awful.

I understand your pain and I fully agree with you. Undocumented API is a known issue, and we are constantly improving the SDK and code documentation. Please note that IntelliJ Platform is a huge project, and this effort takes time. Until then, an additional developers' effort is required.

I can only suggest that the master branch contains the most up-to-date documentation, and I recommend checking out the sources and having them opened next to the plugin project.

Regarding your case, if I understand correctly, you get the parents of the files with the name you are searching for. If this is the case, it looks like an unexpected behavior. I think that in this case, the API is self-explanatory. If you pass the "test" name, I would expect to get files with the "test" name, not their parents. Please share the plugin code (or a minimal plugin that allows us to reproduce the issue) and a minimal reproducible test project we can use for testing the plugin.
It can be shared publicly or via uploads.jetbrains.com (please share the upload ID). Uploaded files are visible only to JetBrains employees.

0

请先登录再写评论。