How to find affected lines of code in every change in every files of the project?

Answered

I need to know some details about user changes in every project files. So I wrote this piece of code in my plugin:

LocalHistoryFacade facade = LocalHistoryImpl.getInstanceImpl().getFacade();
List changeSetList = facade.getChangeListInTests().getChangesInTests();

I have all changes happened in project files in changeSetList variable but I can't find the affected lines of code and the type of change (update, create , delete).
I have a for loop and I use these methods for finding change name (only useful for delete and create files), change timestamp and the afftected file.

changeSetList.get(i).getName()
changeSetList.get(i).getAffectedPaths().get(0)
changeSetList.get(i).getTimestamp()

I need affected lines of code and the type of changes (update, create , delete).

I really appreciate any help you can provide.

1
6 comments

No, it's not possible (it would require us to load whole project content into memory to track changes).

If you do need changed lines, you might look at `com.intellij.openapi.editor.event.DocumentListener`.
For example, you can get `Document` via `FileDocumentManager.getCachedDocument(VirtualFile)` or `FileDocumentManagerListener.fileContentLoaded`.
But it might not be available for external changes (by some tool, other text editor or VCS).

Could you share the purpose, for which you need to observe all changes in a project?

2

Hi,

Could you clarify, what kind of changes do you want to know? Ex: what is the "base version" that is being considered "unchanged" ?

LocalHistory is, likely, a wrong thing to begin with (especially, via @TestOnly methods).

1

Hi,

I need all kinds of changes in the code (insert, update, delete) and creation and deletion of the project files.

If I track the changes from the point which user install the plugin, the base version is the state of the code in plugin installation and if it's possible I prefer to have all changes from the creation of the project. Local history have them all from the beginning.

0

>Local history have them all from the beginning.
The Local History might clear history older than 5 days.

Also, it tracks whole project state, that might not be related to the "user changes". 4ex: switching a branch in VCS will be recorded as a big change in Local History, but it is not a "change in code by user" (if you're trying to track user activity or calculate some statistics).

So, if you want to know all changes from the creation of the project, using VCS would be a better choice.

On the other hand, if you want to track ongoing changes, it's better to listen to VCS or VFS events directly.

0

Finally contentsChanged method of VirtualFileListener worked for me. Now I have a listener which trigger when any kind of modification happen and I have modification type, timestamp and some other information such as file path but still I don't have affected lines of code. Is it possible to find that?

0

Are these APIs still available? I am building a plugin that lets users see their usage of a given library: if the user is using the jdbc mongo connector, for instance(the user called methods on it or instantiated it) i want to track that usage.

0

Please sign in to leave a comment.