Eclipse 插件:在默认代码完成弹出窗口中添加自定义建议 window
Eclipse Plugin: Adding Custom Suggestion in Default Code Completion Pop-up window
我正在制作一个 eclipse 插件,需要在默认的 eclipse 弹出窗口中添加一些自定义建议 window。为此,我是从eclipse doc that I have to implement the IJavaCompletionProposalComputer
to participate in content assist process . Accordingly, I tried the below implementation found in github开始知道的。我知道它覆盖了计算建议的 computeCompletionProposals()
方法和 returns 作为 ICompletionProposal
列表。但是我没能找到如何 在默认弹出窗口中添加我的自定义建议 window。
知道我该怎么做吗?
package zzz.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.contentassist.CompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.ui.texteditor.HippieProposalProcessor;
import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer;
import java.util.*;
/**
* Our sample handler extends AbstractHandler, an IHandler base class.
* @see org.eclipse.core.commands.IHandler
* @see org.eclipse.core.commands.AbstractHandler
*/
/**
* A computer wrapper for the hippie processor.
*
* @since 3.2
*/
public final class HippieProposalComputer implements IJavaCompletionProposalComputer {
/** The wrapped processor. */
private final HippieProposalProcessor fProcessor= new HippieProposalProcessor();
/**
* Default ctor to make it instantiatable via the extension mechanism.
*/
public HippieProposalComputer() {
}
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposalComputer#computeCompletionProposals(org.eclipse.jface.text.contentassist.TextContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
return Arrays.asList(fProcessor.computeCompletionProposals(context.getViewer(), context.getInvocationOffset()));
}
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposalComputer#computeContextInformation(org.eclipse.jface.text.contentassist.TextContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
return Arrays.asList(fProcessor.computeContextInformation(context.getViewer(), context.getInvocationOffset()));
}
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposalComputer#getErrorMessage()
*/
@Override
public String getErrorMessage() {
return fProcessor.getErrorMessage();
}
/*
* @see org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer#sessionStarted()
*/
@Override
public void sessionStarted() {
}
/*
* @see org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer#sessionEnded()
*/
@Override
public void sessionEnded() {
}
}
我的plugin.xml
如下...
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
id="WordCompletionProposalComputer"
name="Word Completion Proposal Computer">
<javaCompletionProposalComputer
class="org.eclipse.jdt.internal.ui.text.java.HippieProposalComputer"
categoryId="org.eclipse.ui.texteditor.textual_proposals">
<partition type="__java_javadoc"/>
</javaCompletionProposalComputer>
</extension>
<extension
point="org.eclipse.ui.commands">
<category
name="Sample Category"
id="zadawdaw.commands.category">
</category>
<command
name="Sample Command"
categoryId="zadawdaw.commands.category"
id="zadawdaw.commands.sampleCommand">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="zadawdaw.commands.sampleCommand"
class="zadawdaw.handlers.SampleHandler">
</handler>
</extension>
<extension point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
id="textual_proposals"
name="Text Proposals">
<proposalCategory icon="icons/wordcompletions.png"/>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
label="Sample Menu"
mnemonic="M"
id="zadawdaw.menus.sampleMenu">
<command
commandId="zadawdaw.commands.sampleCommand"
mnemonic="S"
id="zadawdaw.menus.sampleCommand">
</command>
</menu>
</menuContribution>
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="zadawdaw.toolbars.sampleToolbar">
<command
commandId="zadawdaw.commands.sampleCommand"
icon="icons/sample.png"
tooltip="Say hello world"
id="zadawdaw.toolbars.sampleCommand">
</command>
</toolbar>
</menuContribution>
</extension>
</plugin>
到目前为止的主要错误似乎是将提案提供者限制为分区类型 __java_javadoc
。
您已经(几乎?)在 right place - look for type
. Please see that this definition also refers to IJavaPartitions 中查看了。简而言之,分区是指编辑器中的文本段。链接界面列出了可能的常量以及简短的描述。
如果您希望在编辑 Java 代码时建议补全,请尝试 IJavaPartitions.JAVA_PARTITIONING
。
我正在制作一个 eclipse 插件,需要在默认的 eclipse 弹出窗口中添加一些自定义建议 window。为此,我是从eclipse doc that I have to implement the IJavaCompletionProposalComputer
to participate in content assist process . Accordingly, I tried the below implementation found in github开始知道的。我知道它覆盖了计算建议的 computeCompletionProposals()
方法和 returns 作为 ICompletionProposal
列表。但是我没能找到如何 在默认弹出窗口中添加我的自定义建议 window。
知道我该怎么做吗?
package zzz.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.contentassist.CompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.ui.texteditor.HippieProposalProcessor;
import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer;
import java.util.*;
/**
* Our sample handler extends AbstractHandler, an IHandler base class.
* @see org.eclipse.core.commands.IHandler
* @see org.eclipse.core.commands.AbstractHandler
*/
/**
* A computer wrapper for the hippie processor.
*
* @since 3.2
*/
public final class HippieProposalComputer implements IJavaCompletionProposalComputer {
/** The wrapped processor. */
private final HippieProposalProcessor fProcessor= new HippieProposalProcessor();
/**
* Default ctor to make it instantiatable via the extension mechanism.
*/
public HippieProposalComputer() {
}
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposalComputer#computeCompletionProposals(org.eclipse.jface.text.contentassist.TextContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
return Arrays.asList(fProcessor.computeCompletionProposals(context.getViewer(), context.getInvocationOffset()));
}
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposalComputer#computeContextInformation(org.eclipse.jface.text.contentassist.TextContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
return Arrays.asList(fProcessor.computeContextInformation(context.getViewer(), context.getInvocationOffset()));
}
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposalComputer#getErrorMessage()
*/
@Override
public String getErrorMessage() {
return fProcessor.getErrorMessage();
}
/*
* @see org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer#sessionStarted()
*/
@Override
public void sessionStarted() {
}
/*
* @see org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer#sessionEnded()
*/
@Override
public void sessionEnded() {
}
}
我的plugin.xml
如下...
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
id="WordCompletionProposalComputer"
name="Word Completion Proposal Computer">
<javaCompletionProposalComputer
class="org.eclipse.jdt.internal.ui.text.java.HippieProposalComputer"
categoryId="org.eclipse.ui.texteditor.textual_proposals">
<partition type="__java_javadoc"/>
</javaCompletionProposalComputer>
</extension>
<extension
point="org.eclipse.ui.commands">
<category
name="Sample Category"
id="zadawdaw.commands.category">
</category>
<command
name="Sample Command"
categoryId="zadawdaw.commands.category"
id="zadawdaw.commands.sampleCommand">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="zadawdaw.commands.sampleCommand"
class="zadawdaw.handlers.SampleHandler">
</handler>
</extension>
<extension point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
id="textual_proposals"
name="Text Proposals">
<proposalCategory icon="icons/wordcompletions.png"/>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
label="Sample Menu"
mnemonic="M"
id="zadawdaw.menus.sampleMenu">
<command
commandId="zadawdaw.commands.sampleCommand"
mnemonic="S"
id="zadawdaw.menus.sampleCommand">
</command>
</menu>
</menuContribution>
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="zadawdaw.toolbars.sampleToolbar">
<command
commandId="zadawdaw.commands.sampleCommand"
icon="icons/sample.png"
tooltip="Say hello world"
id="zadawdaw.toolbars.sampleCommand">
</command>
</toolbar>
</menuContribution>
</extension>
</plugin>
到目前为止的主要错误似乎是将提案提供者限制为分区类型 __java_javadoc
。
您已经(几乎?)在 right place - look for type
. Please see that this definition also refers to IJavaPartitions 中查看了。简而言之,分区是指编辑器中的文本段。链接界面列出了可能的常量以及简短的描述。
如果您希望在编辑 Java 代码时建议补全,请尝试 IJavaPartitions.JAVA_PARTITIONING
。