Receiving VcsUser instance

已回答

Hello everyone!
I want to get the instance of VcsUser class for:
1) user who last edited the line of code where the caret is located now
2) authorized user of this project

Now I can receive DiffContent instance for concrete line, maybe it can be helpful:

Project project = e.getProject();
Document document = e.getData(PlatformDataKeys.EDITOR).getDocument();

int offset = e.getData(PlatformDataKeys.CARET).getOffset();
int lineNumber = document.getLineNumber(offset);
TextRange textRange = DocumentUtil.getLineTextRange(document, lineNumber);

DiffContent diffContent = DiffContentFactory.getInstance().createFragment(project, document, textRange);

Can you please describe the approximate way to achieve it?

0

Spolutrean,

I have noticed that you have removed the previous thread in which we had the conversation two days before and created a new one with the same question - this is not, how it should work.

0
Avatar
Permanently deleted user

The previous thread was marked as Answered, but I still didn't have a solution.
I didn't find a way to contact you directly or remove the tag Answered.
I thought that if a post is marked as Answered, then the discussion in it is over.

I apologize for this, I asked a question in that thread and didn't get an answer. Because of this, I decided it would be better to create new ones and continue with it.

0

>maybe it can be helpful:
Probably, it won't be - DiffContent is used to show "diff windows".

First, you need to get registered VCS root for the file in context:

val file = FileDocumentManager.getFile(editor.getDocument)
val repository = GitRepositoryManager.getInstance(project).getRepositoryForFile(file)
val vcsRoot = repository.root

>authorized user of this project

GitUserRegistry.getInstance(project).getOrReadUser(vcsRoot)

>user who last edited the line of code where the caret is located now

val annotationProvider = GitVcs.getInstance(project).getAnnotationProvider()
val fileAnnotation = annotationProvider.annotate(file) as GitFileAnnotation
val info = fileAnnotation.getLineInfo(editor.getCaretModel().getLogicalPosition().line)
val author : String = info.getAuthor() // author email / VcsUser are not accessible from API

You can also use GitHandler and invoke/parse `git blame` command manually. And create VcsUser with VcsUserRegistry#createUser.

1
Avatar
Permanently deleted user

Thank you a lot!

0

UPD: GitFileAnnotation will return data for lines in HEAD revision (just like 'git blame' does).
These might not be the same if file has uncommitted changes.

So you might need to transfer line number using 

val lineNumberProvider = UpToDateLineNumberProviderImpl(editor.getDocument(), project)
val lineNumberInHead = lineNumberProvider.getLineNumber(editor.getCaretModel().getLogicalPosition().line)
1

请先登录再写评论。