mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 03:45:35 +02:00
Hooked up the template engine to the new content assist processor.
This commit is contained in:
parent
f8da9f5f4e
commit
2e76470f0f
5 changed files with 36 additions and 2 deletions
|
@ -1354,6 +1354,10 @@
|
||||||
class="org.eclipse.cdt.internal.ui.text.contentassist.DOMCompletionContributor"
|
class="org.eclipse.cdt.internal.ui.text.contentassist.DOMCompletionContributor"
|
||||||
id="DOM"
|
id="DOM"
|
||||||
priority="1"/>
|
priority="1"/>
|
||||||
|
<contributor
|
||||||
|
class="org.eclipse.cdt.internal.ui.text.template.TemplateEngine"
|
||||||
|
id="CodeTemplates"
|
||||||
|
priority="2"/>
|
||||||
</extension>
|
</extension>
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class CCompletionProcessor2 implements IContentAssistProcessor {
|
||||||
if (!(contribObject instanceof ICompletionContributor))
|
if (!(contribObject instanceof ICompletionContributor))
|
||||||
continue;
|
continue;
|
||||||
ICompletionContributor contributor = (ICompletionContributor)contribObject;
|
ICompletionContributor contributor = (ICompletionContributor)contribObject;
|
||||||
contributor.contributeCompletionProposals(viewer, offset, completionNode, proposals);
|
contributor.contributeCompletionProposals(viewer, offset, workingCopy, completionNode, proposals);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||||
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||||
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
|
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
@ -36,6 +37,7 @@ public class DOMCompletionContributor implements ICompletionContributor {
|
||||||
|
|
||||||
public void contributeCompletionProposals(ITextViewer viewer,
|
public void contributeCompletionProposals(ITextViewer viewer,
|
||||||
int offset,
|
int offset,
|
||||||
|
IWorkingCopy workingCopy,
|
||||||
ASTCompletionNode completionNode,
|
ASTCompletionNode completionNode,
|
||||||
List proposals) {
|
List proposals) {
|
||||||
if (completionNode != null) {
|
if (completionNode != null) {
|
||||||
|
|
|
@ -9,13 +9,17 @@ package org.eclipse.cdt.internal.ui.text.template;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
|
import org.eclipse.cdt.internal.corext.template.c.CContextType;
|
||||||
import org.eclipse.cdt.internal.corext.template.c.TranslationUnitContext;
|
import org.eclipse.cdt.internal.corext.template.c.TranslationUnitContext;
|
||||||
import org.eclipse.cdt.internal.corext.template.c.TranslationUnitContextType;
|
import org.eclipse.cdt.internal.corext.template.c.TranslationUnitContextType;
|
||||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||||
import org.eclipse.cdt.internal.ui.text.c.hover.SourceViewerInformationControl;
|
import org.eclipse.cdt.internal.ui.text.c.hover.SourceViewerInformationControl;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.cdt.ui.text.ICCompletionProposal;
|
import org.eclipse.cdt.ui.text.ICCompletionProposal;
|
||||||
|
import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor;
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.IInformationControl;
|
import org.eclipse.jface.text.IInformationControl;
|
||||||
|
@ -33,7 +37,7 @@ import org.eclipse.swt.graphics.Image;
|
||||||
import org.eclipse.swt.graphics.Point;
|
import org.eclipse.swt.graphics.Point;
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
|
||||||
public class TemplateEngine {
|
public class TemplateEngine implements ICompletionContributor {
|
||||||
|
|
||||||
private TemplateContextType fContextType;
|
private TemplateContextType fContextType;
|
||||||
private ArrayList fProposals= new ArrayList();
|
private ArrayList fProposals= new ArrayList();
|
||||||
|
@ -78,6 +82,17 @@ public class TemplateEngine {
|
||||||
fContextType= contextType;
|
fContextType= contextType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the default constructor used by the new content assist extension point
|
||||||
|
*/
|
||||||
|
public TemplateEngine() {
|
||||||
|
fContextType = CUIPlugin.getDefault().getTemplateContextRegistry().getContextType(CContextType.CCONTEXT_TYPE);
|
||||||
|
if (fContextType == null) {
|
||||||
|
fContextType= new CContextType();
|
||||||
|
CUIPlugin.getDefault().getTemplateContextRegistry().addContextType(fContextType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empties the collector.
|
* Empties the collector.
|
||||||
*
|
*
|
||||||
|
@ -132,5 +147,16 @@ public class TemplateEngine {
|
||||||
fProposals.add(new CTemplateProposal(templates[i], context, region, CPluginImages.get(CPluginImages.IMG_OBJS_TEMPLATE)));
|
fProposals.add(new CTemplateProposal(templates[i], context, region, CPluginImages.get(CPluginImages.IMG_OBJS_TEMPLATE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void contributeCompletionProposals(ITextViewer viewer,
|
||||||
|
int offset,
|
||||||
|
IWorkingCopy workingCopy,
|
||||||
|
ASTCompletionNode completionNode,
|
||||||
|
List proposals)
|
||||||
|
{
|
||||||
|
// TODO We should use the completion node to determine the proper context for the templates
|
||||||
|
// For now we just keep the current behavior
|
||||||
|
complete(viewer, offset, workingCopy);
|
||||||
|
proposals.addAll(fProposals);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ package org.eclipse.cdt.ui.text.contentassist;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||||
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.jface.text.ITextViewer;
|
import org.eclipse.jface.text.ITextViewer;
|
||||||
|
|
||||||
public interface ICompletionContributor {
|
public interface ICompletionContributor {
|
||||||
|
@ -25,6 +26,7 @@ public interface ICompletionContributor {
|
||||||
*/
|
*/
|
||||||
void contributeCompletionProposals(ITextViewer viewer,
|
void contributeCompletionProposals(ITextViewer viewer,
|
||||||
int offset,
|
int offset,
|
||||||
|
IWorkingCopy workingCopy,
|
||||||
ASTCompletionNode completionNode,
|
ASTCompletionNode completionNode,
|
||||||
List proposals);
|
List proposals);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue