CommitSession implementation questions

For the most part the ability to provide your own CommitSession implementation
in a plugin works well. However I have a couple of questions/problems:

- if I return null from CommitSession.getAdditionalConfigurationUI() IDEA
barfs with a NullPointerException. If I return a JComponent, IDEA displays
an additional dialog containing that component. I think returning null should
just silently prevent that dialog from being shown (I don't want this dialog
to appear). Is this a bug?

- what is the correct way to find the differences between revisions for a
given Change object in the execute() method? getBeforeRevision().getFile().getDocument()
and getAfterRevision().getFile().getDocument() both return the same (current)
version of the document. getBeforeRevision().getContent() and getAfterRevision().getContent()
work, however they're both just returned as a String so to pass the individual
lines of text into Diff.buildChanges(beforeLines, afterLines) I have to parse
out all the linefeeds first. Also, getContent() seems to retrieve the revision
from the codestore. What I'd really like is access to whatever it is IDEA
uses to color-code the left hand margin to indicate which lines have been
changed/inserted/deleted for each open file. Obviously the information already
exists somewhere, I just can't see a way to access it.

Any comments/tips appreciated!

Chris


2 comments

Hello Chris,

CM> For the most part the ability to provide your own CommitSession
CM> implementation in a plugin works well. However I have a couple of
CM> questions/problems:
CM>
CM> - if I return null from CommitSession.getAdditionalConfigurationUI()
CM> IDEA barfs with a NullPointerException. If I return a JComponent,
CM> IDEA displays an additional dialog containing that component. I
CM> think returning null should just silently prevent that dialog from
CM> being shown (I don't want this dialog to appear). Is this a bug?

Yes. It'll be fixed in a bugfix update.
http://www.jetbrains.net/jira/browse/IDEADEV-10588

CM> - what is the correct way to find the differences between revisions
CM> for a given Change object in the execute() method?
CM> getBeforeRevision().getFile().getDocument() and
CM> getAfterRevision().getFile().getDocument() both return the same
CM> (current) version of the document. getBeforeRevision().getContent()
CM> and getAfterRevision().getContent() work, however they're both just
CM> returned as a String so to pass the individual lines of text into
CM> Diff.buildChanges(beforeLines, afterLines) I have to parse out all
CM> the linefeeds first. Also, getContent() seems to retrieve the
CM> revision from the codestore. What I'd really like is access to
CM> whatever it is IDEA uses to color-code the left hand margin to
CM> indicate which lines have been changed/inserted/deleted for each
CM> open file. Obviously the information already exists somewhere, I
CM> just can't see a way to access it.

Well, it doesn't exist in a direct way. The "Show Diff" action in the Changes
view builds a DiffRequest with two DiffContent instances, and the differences
themselves are calculated by the diff engine.

Here's how a DiffContent is created:

private static DiffContent createContent(Project project, ContentRevision
revision) {
if (revision == null) return new SimpleContent("");
if (revision instanceof CurrentContentRevision) {
final CurrentContentRevision current = (CurrentContentRevision)revision;
final VirtualFile vFile = current.getVirtualFile();
return vFile != null ? new FileContent(project, vFile) : new SimpleContent("");
}

final String revisionContent = revision.getContent();
SimpleContent content = revisionContent == null
? new SimpleContent("")
: new SimpleContent(revisionContent, revision.getFile().getFileType());
content.setReadOnly(true);
return content;
}


--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Yes. It'll be fixed in a bugfix update.
http://www.jetbrains.net/jira/browse/IDEADEV-10588


Thanks, and I see you've fixed it already! Looking forward to 6.0.1.

Well, it doesn't exist in a direct way. The "Show Diff" action in the
Changes view builds a DiffRequest with two DiffContent instances, and
the differences themselves are calculated by the diff engine.

Here's how a DiffContent is created:


]]>

Ahh I see, thanks for the insight on this one. Looks like that lets me get
rid of all the nasty linefeed parsing code I currently have! I guess I'm
still curious as to why that code is required when it seems to me the diffs
must exist somewhere already anyway - otherwise how is IDEA able to provide
all the coloring and ctrl-alt-shift-up/down functionality? Note that for
my purposes I'm not interested in diffs at anything finer grained than on
a per-line basis (which is exactly what Diff.buildChanges() gives me). Your
diff view obviously shows more detail than that so I can appreciate that
there's extra code required there.

Thanks kindly for your help,
Chris


0

Please sign in to leave a comment.