VCS: Changes in file

Hi,

at the moment I try to create a small plugin that reformats only those
parts of the file that are already "touched"...

How can I find those lines within a file that have been changed - and
how can I find the corresponding PsiElements for those lines?


Johannes Schneider

4 comments

Johannes Schneider wrote:

Hi,

at the moment I try to create a small plugin that reformats only those
parts of the file that are already "touched"...

How can I find those lines within a file that have been changed - and
how can I find the corresponding PsiElements for those lines?


Johannes Schneider


I'm not familiar with this API but you probably want to start with
VcsManager.getInstance(project).getActiveVcs(). I looked around and I
couldn't find something that looks like the API used to show the changes
in the gutter, but you could probably use getDiffProvider(). To find
PsiElements, you can call psifile.findElementAt(offset), where offset is
a character offset into the file.

0

Hi,

Keith Lea wrote:

I'm not familiar with this API but you probably want to start with
VcsManager.getInstance(project).getActiveVcs(). I looked around and I


Yes, found this.

couldn't find something that looks like the API used to show the changes
in the gutter, but you could probably use getDiffProvider(). To find
PsiElements, you can call psifile.findElementAt(offset), where offset is
a character offset into the file.


Okay, "manual processing"... :(



Johannes Schneider

0

Hello Johannes,

JS> at the moment I try to create a small plugin that reformats only
JS> those parts of the file that are already "touched"...
JS>
JS> How can I find those lines within a file that have been changed -
JS> and how can I find the corresponding PsiElements for those lines?

The IDEA line status tracker uses the com.intellij.util.diff.Diff class to
calculate the difference between revisions, and builds the changed lines
list from the diff result. The revision to compare the current document contents
with can be taken from AbstractVcs.getUpToDateRevisionProvider().getLastUpToDateContentFor().


--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

Dmitry Jemerov (JetBrains) wrote:

Hello Johannes,

JS> at the moment I try to create a small plugin that reformats only
JS> those parts of the file that are already "touched"...
JS> JS> How can I find those lines within a file that have been changed -
JS> and how can I find the corresponding PsiElements for those lines?

The IDEA line status tracker uses the com.intellij.util.diff.Diff class
to calculate the difference between revisions, and builds the changed
lines list from the diff result. The revision to compare the current
document contents with can be taken from
AbstractVcs.getUpToDateRevisionProvider().getLastUpToDateContentFor().


Thank you for your reply - but I think I need more informations, maybe
you can help me?

I tried the following code, but the "Diff.Change" does not give me
anything that I understand.



UpToDateRevisionProvider upToDateRevisionProvider =
activeVcs.getUpToDateRevisionProvider();

String lastUpToDateContent =
upToDateRevisionProvider.getLastUpToDateContentFor(
psiFile.getVirtualFile(), true ); //This string looks good

Language language = psiFile.getLanguage();
ParserDefinition parserDefinition = language.getParserDefinition();

PsiFile lastUpToDateFile = parserDefinition.createFile( project,
psiFile.getName(), lastUpToDateContent ); //is that the way to go?

Diff.Change change = Diff.buildChanges( lastUpToDateFile.getChildren(),
psiFile.getChildren() );
//the change always reports inserted=6, deleted=6, line0=0, line1=0 (on
unchanged files too)


I think I should call Diff.buildChanges with other parameters, can you
help me?



Thanks,

Johannes Schneider

0

Please sign in to leave a comment.