Filtering files in commit by programming language

Answered

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.

0
3 comments

com.intellij.openapi.vcs.changes.Change#getVirtualFile ->

com.intellij.psi.PsiManager#findViewProvider ->

com.intellij.psi.FileViewProvider#getBaseLanguage/getLanguages

0

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?

0

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?

find out a programming language used in this file without name (therefore, I can't simply look for file extension
0

Please sign in to leave a comment.