VcsUtil.getVcsFor return null
Answered
I want to get abstractVcs when user view at git log tab.
I can not get vcs info.
VcsUtil.getVcsFor(project, virtualFile)
if user view at editor,can get vcs info well.
I am writing a plugin which recored bookmark and annotate author.
Please sign in to leave a comment.
`VirtualFile` that is shown in diff viewer does not belong to LocalFileSystem.
`VcsUtil.getVcsFor(project, virtualFile)` returns `null` for such files, as they are not under VCS (ex: you can't change & commit them).
What do you need this `AbstractVcs` for?
I need the right line's annotate info in the diff viewer
There are no handy API to get this info.
You can take a look at implementation of `com.intellij.openapi.vcs.actions.AnnotateDiffViewerAction`. Notably, `collectEventData` and `createTwosideAnnotationsLoader` methods.
`BookmarksListener` has no Editor in context (and single `VirtualFile`/`Document` might be shown multiple times). See `com.intellij.openapi.editor.EditorFactory#getEditors(Document)` that returns all editors for a file.
See also `com.intellij.ide.DataManager#getDataContext(Component)` to get DataContext for specific Editor.
Note, that you might want to use GitHandler directly (ex: performing a request like `git log -n 1 -L 123,123:file-path.txt`) instead of `AnnotationProvider`, as this request might be faster than loading annotations.
I will has a try to execute git shell command
How to get the right view revision number or commit number?
I decide to use git handler command to get annotate info
Since I already wasted my time on this, I'll put my solution here:
It needs a change in IntelliJ: https://github.com/JetBrains/intellij-community/compare/192...krasa:diffRevision
Then it would probably be possible to go Bookmark->VirtualFile -> Document-> Editor-> DocumentContent-> revision (if null then it is the current one)
you should submit the pull request.
and if pr is accepted, I need wait idea release new version?
No, you should, after you try that it is really what you need. :)
And yes.