Filtering files in commit by programming language
Hello.
I am developing a plugin, which interacts with Git VCS and I wondering if there a simple way to find out a programming language used in this file without name (therefore, I can't simply look for file extension in file name).
Because of my plugin processing commits found in project's history (represented by ```GitCommit``` objects) and commits made from IntelliJ UI (represented by ```Change``` objects collection obtained from ```CheckinPanel```), I need to be able to figure out a file language from ```Change``` object somehow.
If there is a some magic utils class which would allow me to write something like
```
commit.getChanges().stream().filter(x -> SomeMagicUtilsClass.getFIleLanguage(x).equals(Java.INSTANCE)....;
```
it would be totally a charm!
Thanks.
Please sign in to leave a comment.
com.intellij.openapi.vcs.changes.Change#getVirtualFile ->
com.intellij.psi.PsiManager#findViewProvider ->
com.intellij.psi.FileViewProvider#getBaseLanguage/getLanguages
Thank you for answer, Yann!
But for old revisions getVirtualFile() returns null, if this file was moved/deleted later. How should I handle this in such cases?
Then you could only guess language via filename/extension from com.intellij.openapi.vcs.changes.ChangesUtil#getFilePath
Sorry, it seems that won't cover your case, could you give a sample of such file? What is the purpose of detecting the language?