Want to use Diff View component

Hi - I would like to display the Diff between two files in the IDEA Difference View, from my own program. I hope to get the correct source from the community edition and just do a simple call to launch the diff window. Where do I start looking please? Which packages and classes implement the diff view? Many thanks, Anthony

11 comments
Comment actions Permalink

Hello Anthony,

Our diff view depends on quite a lot of stuff - our component model, our
editors framework, our action system, virtual file system etc. So it may
not be as easy as it seems to be.

The starting point for looking is the DiffPanelImpl class in the CE source.

Hi - I would like to display the Diff between two files in the IDEA
Difference View, from my own program. I hope to get the correct source
from the community edition and just do a simple call to launch the
diff window. Where do I start looking please? Which packages and
classes implement the diff view? Many thanks, Anthony


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Dmitry, could I commission someone at IntelliJ to supply with a jar that wraps it all up and just has one method compare(File f1, File f2) ? I can pay via PayPal.

0
Comment actions Permalink

Hello Anthony,

I don't think we provide custom development services like that.

Dmitry, could I commission someone at IntelliJ to supply with a jar
that wraps it all up and just has one method compare(File f1, File f2)
? I can pay via PayPal.


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

IGNORE FOR NOW... structure looks quite logical. (Dmitry, could you direct me to instructions on how to get from unpacked source tarball to mounted source with no compile errors? I see some idea iml files in the source, but am not sure where all the libraries etc. are. Thanks.)

0
Comment actions Permalink

Hello Anthony,

The source tarball is a directory-based project, so you can open the root
directory of the tarball as a project and compile it. It contains all the
necessary library definitions, except for a JDK (you'll need to define a
JDK named 'IDEA jdk' and add tools.jar from the JDK library directory to
its classpath). See http://www.jetbrains.org/ for further instructions.

Dmitry, could you direct me to instructions on how to get from
unpacked source tarball to mounted source with no compile errors? I
see some idea iml files in the source, but am not sure where all the
libraries etc. are. Thanks.


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hi Dmitry

Getting the source mounted and running was easy, thanks. The instructions were clear etc.

I'm struggling though to get the code into a state where I can successfully make the call
DiffManager.getInstance().getDiffTool().show(diffData);

In fact, I can't create an instance of SimpleContect because there is no editor factory. EditorFactory getInstance() is null even after normal startup.

Any hints? Or pointers to documentation that would give me a clearer idea of how idea starts up? I am starting to wonder whether it would be easier to incorporate my tool into a plugin, so perhaps I should be reading the Plugin guides. Any suggestions would be appreciated.

The image below is also present as an attachment.

Thanks,
Anthony

0001.jpg



Attachment(s):
0001.jpg
0
Comment actions Permalink

Hello Anthony,

EditorFactory is an application component. To initialize the application
components, you need to initialize the entire IDEA application. See ApplicationManagerEx.createApplication()
to see how IDEA itself does that.

Note that you may be able to remove most of the components registered in
IDEA .xml files (IdeaPlugin.xml and the files included from it) because most
of them aren't needed to show the diff.

Implementing your tool as a plugin will most likely be much easier. See http://confluence.jetbrains.net/display/IDEADEV/PluginDevelopment
for the starting point of the plugin development documentation.

Getting the source mounted and running was easy, thanks. The
instructions were clear etc.

I'm struggling though to get the code into a state where I can
successfully make the call
DiffManager.getInstance().getDiffTool().show(diffData);
In fact, I can't create an instance of SimpleContect because there is
no editor factory. EditorFactory getInstance() is null even after
normal startup.

Any hints? Or pointers to documentation that would give me a clearer
idea of how idea starts up? I am starting to wonder whether it would
be easier to incorporate my tool into a plugin, so perhaps I should be
reading the Plugin guides. Any suggestions would be appreciated.

The image below is also present as an attachment.


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Plugin Dev is dead easy! I hadn't realised. Nicely done Jetbrains.

0
Comment actions Permalink

Dmitry, the diff thing works, but it treats the text I feed it as plain text and I want to be able to control the type (java, xml, or plain would cover most scenarios).

I am using SimpleContent as below, but there is another constructor that takes a parameter FileType: public SimpleContent(@NotNull String text, FileType type)

DiffContent  con1 = new SimpleContent(getContentz(oldFile));
DiffContent  con2 = new SimpleContent(getContentz(newFile));



I cannot access JavaFileType from my Plugin. If I try to add package java-impl (which contains all the FileType subclasses) as a dependency I get weird errors and problems trying to execute.

The files which I am trying to compare are not part of the virtual file system, so I cannot use a VirtualFile. Actually, I can try to construct a LightVirtualFile, using constructor

public LightVirtualFile(final String name, final Language language, final CharSequence text)

but run into a very similar problem: I cannot access JavaLanguage which is the language I would want to pass in as param 2. Even if I write my own implementation of JavaLanguage, I have to reference JavaFileHighlighter which gives the same weird errors when I try to add java-impl as a dependncy. (image attached).

It seems as if I am coming up against something architectural, a boundary I am not supposed to cross for some reason. And yet I know that IDEA can compare two random strings as Java because it does so when I compare two historical files from e.g a Subversion repository.

What is really foreign to me is the way that I put in place a dependency and then find that the editor suggests the import (as suggested) but after I do the import, while the editor references the correct package, it denies knowledge of the actual class/symbol. See the red error in the attached image for an example (public JavaFileHighligher not recognised). I'm not sure what is going on with that, but it seems to be my main obstacle.


Please help.

Thanks,
Anthony


Attachment(s):
0002.jpg
0
Comment actions Permalink

Hello Anthony,

You need to add idea.jar to the classpath of your IDEA JDK. Then you'll be
able to access JavaFileType, JavaLanguage etc.

Dmitry, the diff thing works, but it treats the text I feed it as
plain text and I want to be able to control the type (java, xml, or
plain would cover most scenarious).

I am using SimpleContent as below, but there is another constructor
that takes a parameter FileType: public SimpleContent(@NotNull String
text, FileType type)

DiffContent  con1 = new SimpleContent(getContentz(oldFile));
DiffContent  con2 = new SimpleContent(getContentz(newFile));

I cannot access JavaFileType from my Plugin. If I try to add package
java-impl (which contains all the FileType subclasses) as a dependency
I get weird errors and problems trying to execute.

The files which I am trying to compare are not part of the virtual
file system, so I cannot use a VirtualFile. Actually, I can try to
construct a LightVirtualFile, using constructor

public LightVirtualFile(final String name, final Language language,
final CharSequence text)

but run into a very similar problem: I cannot access JavaLanguage
which is the language I would want to pass in as param 2. Even if I
write my own implementation of JavaLanguage, I have to reference
JavaFileHihglighter which gives the same weird errors when I try to
add java-impl as a dependncy. (image attached).

It seems as if I am coming up against something architectural, a
boundary I am not supposed to cross for some reason. And yet I know
that IDEA can compare two random strings as Java because it does so
when I compare two historical files from e.g a Subversion repository.

Please help.

Thanks,
Anthony
---
Original message URL:
http://devnet.jetbrains.net/message/5280991#5280991


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Great - seems to work. Just to check I've done this correctly: I have added idea.jar to the classpath of (see attached image) IDEA jdk, *not* IDEA IC-99.18, which is the plugin SDK, and uses "IDEA jdk" as its "Internal Java Plafform".

BTW I think the weird errors were caused by circular dependencies. Thanks.



Attachment(s):
0003.jpg
0

Please sign in to leave a comment.