Get Project Type using Open API
Answered
Let's say we open up a new project in the IDE. Can I programmatically get the type of project the current IDE instance is opened for?
I'm asking this in the context of my IntelliJ plugin that can perform some activities based on the project type/project language opened in the currently running IDE instance.
Is there any Open API available to get the Project Language/Type?
Please sign in to leave a comment.
Hi,
There is no universal API, and depending on your use case, different solutions could be used.
Please clarify what types/languages you need to detect.
When I create a Project using Wizard as below, I could see three options (Java, Kotlin,Groovy) to select from. I need to detect which language the project is based off of.
Are there any options to determine this programmatically?
It is not trivial to do, as a single module/project can contain multiple languages. Consider a module with mixed Java and Kotlin, which is a standard situation (and possibly more files, like XML, JSON, HTML).
Still, your use case is unclear to me. Most likely, I would try to check whether a module or project contains files in the language you need to check and perform the required action based on this information.
Checking can be done, for example, with
com.intellij.psi.search.FileTypeIndex.It’s a chat assistant plugin. If a user questions or requests anything, depending on the language of the project, the plugin has to respond back in the respective language.
Thanks for highlighting the API. I’ll try it.