How to get the Local History programatically?

Hi,
I’m currently use the code below to get the vcs history:
VcsHistoryProvider historyProvider = vcs.getVcsHistoryProvider();
if (historyProvider == null) {
// Handle the case when there is no history provider
return;
}
FilePath filePath = VcsUtil.getFilePath(file.getPath());

Editor finalEditor = editor;
ApplicationManager.getApplication().executeOnPooledThread(() → {
VcsHistorySession historySession = null;
try {
historySession = historyProvider.createSessionFor(filePath);
} catch (VcsException ex) {}

List revisions = historySession.getRevisionList();
});
How to get the local history of the file?
Thank you very much for any help !

Hello! API for local history might be rather tricky…
You can use LocalHistoryFacade.collectChanges
To obtain LocalHistoryFacade use LocalHistoryImpl.getInstanceImpl

Hi @ilia.shulgin, thanks for your response!
I am getting such error when I tried to call LocalHistoryFacade.collectChanges in Pycharm 2024.3, but it works well in PyCharm 2024.2

java.lang.NoSuchMethodError: 'void com.intellij.history.core.LocalHistoryFacadeKt.collectChanges(com.intellij.history.core.LocalHistoryFacade, java.lang.String, java.lang.String, java.lang.String, kotlin.jvm.functions.Function1)'

Looks like the signature of this method was changed, so how can we use collectChanges with 2024.2 and 2024.3 IDE versions?

You are tight, signature was changed. However, this method simply calls com.intellij.history.core.LocalHistoryFacadeKt#collectChanges(com.intellij.history.core.LocalHistoryFacade, java.lang.String, com.intellij.history.core.ChangeProcessor) passing ChangeProcessorBase there. However, its signature was also changed :smiling_face_with_tear:

So you have to recreate ChangeProcessorBase from 242 (intellij-community/platform/lvcs-impl/src/com/intellij/history/core/LocalHistoryFacade.kt at 242 · JetBrains/intellij-community · GitHub) on your side and pass it to com.intellij.history.core.LocalHistoryFacadeKt#collectChanges(com.intellij.history.core.LocalHistoryFacade, java.lang.String, com.intellij.history.core.ChangeProcessor).

Another (and more preferable option) is creation of 2 plugin builds.

1 Like

Thanks a lot @ilia.shulgin, it makes sense!

I have 2 more questions:

  1. I see that this method intellij-community/platform/lvcs-impl/src/com/intellij/history/core/LocalHistoryFacade.kt at fb1cd60efc41b3b1abad29a5f43e3c803ce09ed9 · JetBrains/intellij-community · GitHub is annotated with @ApiStatus.Internal; won’t this be a problem for the JB plugin review?
  2. Is there a way to support version 2024.1 as well? I mean, if my platformVersion=2024.1.1, will I be able to use localChanges for 241+ versions without creating multiple builds? (Supporting multiple builds is very costly in terms of development time)

@drozdov.gleb.spb sorry, i had to mention it. You are right, it will be blocked by the plugin verifier.
Sadly, there is no option to align API for 241/242/243 and 251.

So the best solution is having 2 builds - for 241/242 using collectChanges with patternString: String? and 243+ using filter: HistoryPathFilter?.

@ilia.shulgin
Hi, when I set platformVersion=251.23774.200 with intellij-gradle-plugin 2.4.0
the com.intellij.history.core and com.intellij.history.integration is no longer exists.
How to solve this? Thank you very much!

Hey, did you ever find a solution for this?