[Eclipse Plug-in Development] expand the code prompt and completion of Eclipse XML Editor

Follow the great God of Wu Xuan Eclipse code prompt and completion plug-in Later, we found that the plug-in extension is the Generic Text Editor (org.eclipse.ui.editors.text.TextEditor) that comes with eclipse, so the scope is limited to this general text editor. After using the Design Page of eclipse's XML Editor (org. Eclipse. WST. XML. UI. Internal. Tabletree. Xmlultipageeditorpart), I feel really delicious. Don't want to build a wheel from scratch, and expand XML code prompt and completion on the basis of Generic Text Editor. At this time, a bold idea arises in my heart: can we learn from all the advantages, and integrate XML editor with custom code prompt and completion plug-ins? In other words, integrating code prompt and completion plug-ins into existing XML editor, or expanding code prompt and completion on the basis of existing XML editor.
First of all, you can see that Eclipse Official FAQ This kind of editor is classified as StructuredTextEditor, and a capital "TODO" below the FAQ is enough to see the complexity of the problem. It's not as easy to write a paragraph in plugin.xml as follows.

<extension point="org.eclipse.ui.genericeditor.contentAssistProcessors">
</extension>

What are the extension points of StructuredTextEditor? After persistent Bing, we can find some documents:

The most valuable is the section in plugin.xml of org.eclipse.wst.xml.ui jar package:

<extension
       point="org.eclipse.wst.sse.ui.completionProposal">
    <proposalCategory
          icon="icons/full/obj16/tag-generic.gif"
          id="org.eclipse.wst.xml.ui.proposalCategory.xmlTags"
          name="%proposalCategory.xmlTags">
    </proposalCategory>
    <proposalCategory
          icon="icons/full/obj16/tag-macro.gif"
          id="org.eclipse.wst.xml.ui.proposalCategory.xmlTemplates"
          name="%proposalCategory.xmlTemplates">
    </proposalCategory>
    <proposalComputer
          activate="false"
          categoryId="org.eclipse.wst.xml.ui.proposalCategory.xmlTags"
          class="org.eclipse.wst.xml.ui.internal.contentassist.XMLTagsCompletionProposalComputer"
          id="org.eclipse.wst.xml.ui.proposalComputer.xmlTags">
       <contentType
             id="org.eclipse.core.runtime.xml">
       </contentType>
    </proposalComputer>
    <proposalComputer
          activate="false"
          categoryId="org.eclipse.wst.xml.ui.proposalCategory.xmlTemplates"
          class="org.eclipse.wst.xml.ui.internal.contentassist.XMLTemplatesCompletionProposalComputer"
          id="org.eclipse.wst.xml.ui.proposalComputer.xmlTemplates">
       <contentType
             id="org.eclipse.core.runtime.xml">
       </contentType>
    </proposalComputer>
 </extension>

Write it in your plugin.xml

<extension point="org.eclipse.wst.sse.ui.completionProposal">
		<proposalComputer
				activate="false"
				categoryId="org.eclipse.wst.xml.ui.proposalCategory.xmlTemplates"
				class="{Your XMLTemplatesCompletionProposalComputer Complete class name}"
				id="org.eclipse.wst.xml.ui.proposalComputer.xmlTemplates">
			<contentType
				id="org.eclipse.core.runtime.xml">
			</contentType>
		</proposalComputer>
	</extension>

Then write your own XMLTemplatesCompletionProposalComputer class extends org.eclipse.wst.xml.ui.internal.contentassist.XMLTemplatesCompletionProposalComputer, override its computecompletionproposalcomputer method, add your own logic, and it's a success! The following is the basic logic. You can see that the code prompt in the XML Templates classification is repeated twice after the code prompt is opened. Modify the basic logic to add your own code prompt.

public class XMLTemplatesCompletionProposalComputer extends org.eclipse.wst.xml.ui.internal.contentassist.XMLTemplatesCompletionProposalComputer {
	@Override
	public List computeCompletionProposals(CompletionProposalInvocationContext context,
			IProgressMonitor monitor) {
		return super.computeCompletionProposals(context, monitor);
	} 
}

If you don't like the feeling of being a host, and want to create your own classification, you can add a proposalCategory element to your plugin.xml, define the id of the classification, and then the attribute of the proposalComputer element, categoryId, uses its own proposalCategory id.
Example: some-browser-eclipse
Note: the example is a plug-in developed to meet personal needs. It integrates many functions needed in its own work, not specifically for the example of this article. However, the functions mentioned in this article have been integrated into this plug-in. Please make good use of the search function to find the code related to this article.

Keywords: Eclipse xml Attribute

Added by virendrachandak on Sat, 04 Jan 2020 06:10:51 +0200