diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index f846b54cc27..ab377bd0748 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -1582,21 +1582,6 @@
name="%CDTIndexer.domsourceindexer"/>
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
0) {
- proposal.setContextInformation(new ContextInformation(fname, fargs));
- // set the cursor before the closing bracket
- proposal.setCursorPosition(fname.length() - 1);
- }
-
- proposals.add(proposal);
- }
-
- }
- }
- }
-
-}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionProposalComputer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionProposalComputer.java
new file mode 100644
index 00000000000..0429b833ddc
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionProposalComputer.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2007 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Bryan Wilkinson (QNX) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.text.contentassist;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.swt.graphics.Image;
+
+import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
+import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.IFunctionSummary;
+import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
+
+import org.eclipse.cdt.internal.ui.CHelpProviderManager;
+import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
+
+public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer {
+
+ protected List computeCompletionProposals(
+ CContentAssistInvocationContext cContext,
+ ASTCompletionNode completionNode, String prefix)
+ throws CoreException {
+
+ boolean handleHelp = false;
+ if (completionNode != null) {
+ IASTName[] names = completionNode.getNames();
+ for (int i = 0; i < names.length; ++i) {
+ IASTName name = names[i];
+
+ // ignore if not connected
+ if (name.getTranslationUnit() == null)
+ continue;
+
+ // ignore if this is a member access
+ if (name.getParent() instanceof IASTFieldReference)
+ continue;
+
+ handleHelp = true;
+ break;
+ }
+ }
+
+ if (!handleHelp) {
+ return Collections.EMPTY_LIST;
+ }
+
+ final ITranslationUnit tu = cContext.getTranslationUnit();
+ // Find matching functions
+ ICHelpInvocationContext helpContext = new ICHelpInvocationContext() {
+
+ public IProject getProject() {
+ return tu.getCProject().getProject();
+ }
+
+ public ITranslationUnit getTranslationUnit() {
+ return tu;
+ }
+ };
+
+ IFunctionSummary[] summaries = CHelpProviderManager.getDefault()
+ .getMatchingFunctions(helpContext, prefix);
+ if (summaries == null)
+ return Collections.EMPTY_LIST;
+
+ int repOffset = cContext.getInvocationOffset() - prefix.length();
+ int repLength = prefix.length();
+ Image image = CUIPlugin.getImageDescriptorRegistry().get(
+ CElementImageProvider.getFunctionImageDescriptor());
+
+ List proposals = new ArrayList();
+
+ for (int j = 0; j < summaries.length; j++) {
+ IFunctionSummary summary = summaries[j];
+ String fname = summary.getName() + "()"; //$NON-NLS-1$
+ String fdesc = summary.getDescription();
+ IFunctionSummary.IFunctionPrototypeSummary fproto = summary
+ .getPrototype();
+ String fargs = fproto.getArguments();
+
+ CCompletionProposal proposal;
+ proposal = new CCompletionProposal(
+ fname,
+ repOffset,
+ repLength,
+ image,
+ fproto.getPrototypeString(true),
+ 2,
+ cContext.getViewer());
+
+ if (fdesc != null) {
+ proposal.setAdditionalProposalInfo(fdesc);
+ }
+
+ if (!cContext.isContextInformationStyle()) {
+ // set the cursor before the closing bracket
+ proposal.setCursorPosition(fname.length() - 1);
+ }
+
+ if (fargs != null && fargs.length() > 0) {
+ CProposalContextInformation info = new CProposalContextInformation(image, fname, fargs);
+ info.setContextInformationPosition(cContext.getContextInformationOffset());
+ proposal.setContextInformation(info);
+
+ }
+
+ proposals.add(proposal);
+ }
+
+ return proposals;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/KeywordCompletionContributor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/KeywordCompletionProposalComputer.java
similarity index 70%
rename from core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/KeywordCompletionContributor.java
rename to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/KeywordCompletionProposalComputer.java
index 9bacc372a43..39225c59d95 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/KeywordCompletionContributor.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/KeywordCompletionProposalComputer.java
@@ -1,99 +1,106 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 IBM Corporation and others.
+ * Copyright (c) 2007 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
- * Anton Leherbauer (Wind River Systems)
+ * Bryan Wilkinson (QNX) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextUtilities;
+import org.eclipse.swt.graphics.Image;
+
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.core.model.IWorkingCopy;
+import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.Directives;
import org.eclipse.cdt.core.parser.Keywords;
-import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICPartitions;
-import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.TextUtilities;
-import org.eclipse.swt.graphics.Image;
+import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer;
-public class KeywordCompletionContributor implements ICompletionContributor {
+import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
- public void contributeCompletionProposals(ITextViewer viewer, int offset,
- IWorkingCopy workingCopy, ASTCompletionNode completionNode,
- String prefix, List proposals) {
+public class KeywordCompletionProposalComputer extends ParsingBasedProposalComputer implements ICompletionProposalComputer {
- // No prefix, no completions
- if (prefix.length() == 0)
- return;
+ protected List computeCompletionProposals(
+ CContentAssistInvocationContext context,
+ ASTCompletionNode completionNode, String prefix)
+ throws CoreException {
+
+ // No prefix, no completions
+ if (prefix.length() == 0 || context.isContextInformationStyle())
+ return Collections.EMPTY_LIST;
String[] keywords;
- if(inPreprocessorDirective(viewer.getDocument(), offset)) {
+ if(inPreprocessorDirective(context.getDocument(), context.getInvocationOffset())) {
keywords= preprocessorKeywords;
} else {
- if (!validContext(completionNode))
- return;
+ if (!isValidContext(completionNode))
+ return Collections.EMPTY_LIST;
+
+ ITranslationUnit tu = context.getTranslationUnit();
keywords = cppkeywords; // default to C++
- if (workingCopy != null && workingCopy.isCLanguage())
+ if (tu != null && tu.isCLanguage())
keywords = ckeywords;
}
+
+ List proposals = new ArrayList();
+
// add matching keyword proposals
ImageDescriptor imagedesc = CElementImageProvider.getKeywordImageDescriptor();
Image image = imagedesc != null ? CUIPlugin.getImageDescriptorRegistry().get(imagedesc) : null;
for (int i = 0; i < keywords.length; ++i) {
if (keywords[i].startsWith(prefix)) {
int repLength = prefix.length();
- int repOffset = offset - repLength;
- proposals.add(new CCompletionProposal(keywords[i], repOffset, repLength, image, keywords[i], 1, viewer));
+ int repOffset = context.getInvocationOffset() - repLength;
+ proposals.add(new CCompletionProposal(keywords[i], repOffset,
+ repLength, image, keywords[i], 1, context.getViewer()));
}
}
- }
-
- // TODO This is copied from the search completion contributor
- // We should make this common
- private boolean validContext(ASTCompletionNode completionNode) {
- if (completionNode == null)
- // No completion node, assume true
- return true;
-
- boolean valid = true;
- IASTName[] names = completionNode.getNames();
- for (int i = 0; i < names.length; i++) {
- IASTName name = names[i];
-
- // not hooked up, not a valid name, ignore
- if (name.getTranslationUnit() == null)
- continue;
-
- // member access currently isn't valid
- if (name.getParent() instanceof IASTFieldReference) {
- valid = false;
- continue;
- }
-
- // found one that was valid
- return true;
- }
-
- // Couldn't find a valid context
- return valid;
- }
+
+ return proposals;
+ }
+ /**
+ * Checks whether the given invocation context looks valid for template completion.
+ *
+ * @param context the content assist invocation context
+ * @return false
if the given invocation context looks like a field reference
+ */
+ private boolean isValidContext(ASTCompletionNode completionNode) {
+ IASTName[] names = completionNode.getNames();
+ for (int i = 0; i < names.length; ++i) {
+ IASTName name = names[i];
+
+ // ignore if not connected
+ if (name.getTranslationUnit() == null)
+ continue;
+
+ // ignore if this is a member access
+ if (name.getParent() instanceof IASTFieldReference)
+ continue;
+
+ return true;
+ }
+
+ return false;
+ }
+
/**
* Check if given offset is inside a preprocessor directive.
*
@@ -112,7 +119,7 @@ public class KeywordCompletionContributor implements ICompletionContributor {
}
return false;
}
-
+
// These are the keywords we complete
// We only do the ones that are >= 5 characters long
private static String [] ckeywords = {
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/LegacyCompletionProposalComputer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/LegacyCompletionProposalComputer.java
index 1c65d7d054e..9090d33c497 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/LegacyCompletionProposalComputer.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/LegacyCompletionProposalComputer.java
@@ -13,6 +13,7 @@
package org.eclipse.cdt.internal.ui.text.contentassist;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
@@ -45,6 +46,10 @@ public class LegacyCompletionProposalComputer extends ParsingBasedProposalComput
CContentAssistInvocationContext context,
ASTCompletionNode completionNode, String prefix) throws CoreException {
+ if (context.isContextInformationStyle()) {
+ // context information cannot be supported by completionContributors
+ return Collections.EMPTY_LIST;
+ }
ITextViewer viewer = context.getViewer();
int offset = context.getInvocationOffset();
IWorkingCopy workingCopy = context.getTranslationUnit().getWorkingCopy();