views:

129

answers:

4

Hello,

I wonder how eclipse editor works to enable code assistance?
For example: XML editor for hibernate property file.
Within the editor, if I ctrl-space within a tag, a list of possible value relevant to hibernate will show up.

alt text

I understand that the xml editor is pre-configured to understand xml tag, but how about tag specific to a particular framework?

Can you explain the process? why this happen?

A: 

If you're interested in writing your own content assistants, you may want to start by reading the following:

http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/editors_contentassist.htm

In a nutshell, like most things in Eclipse, this is a platform hook. When you press the button, it queries all the registered assistants (I'm simplifying here), and they provide suggestions based on the current element or even the current content.

When writing a source editor or viewer for a particular language or document type, it is common to provide at least some rudimentary content assistants.

Uri
A: 

To add to Uri's answer, you can define your own editor for your own language with XText as long as you have a simple EBNF grammar language for your DSL (domain specific language).

alt text

You will have:

  • syntax coloring,
  • model navigation (F3, etc.),
  • code completion,
  • outline view, and
  • code templates.
VonC
+1  A: 

I believe that the eclipse XML editor gets the content assist information from any referenced DTDs, or XMLSchema information it associates with the XML file. Try this experiment: Remove the DOCTYPE entry at the beginning of the file and see if content assist still works.

ChrisH
A: 

Removed the DOCTYPE entry at the beginning of the file and im now able to see the commands while typing ctrl+space...

Regards, Vignesh.R

Vignesh