Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2005-07-06 15:52:16 -0400
committerDoug Schaefer2005-07-06 15:52:16 -0400
commit46807db5b9101064b73f220b1c1d693d345add2a (patch)
treef4b288f6da33af267d0ada6330b751ee6a15dbcb
parent41006ecdd04b1867a5bd5a11e9be67dd8a0bc205 (diff)
downloadorg.eclipse.cdt-46807db5b9101064b73f220b1c1d693d345add2a.tar.gz
org.eclipse.cdt-46807db5b9101064b73f220b1c1d693d345add2a.tar.xz
org.eclipse.cdt-46807db5b9101064b73f220b1c1d693d345add2a.zip
Bug 98881 - Added lots of goodies to the search completion to make it more usable. Put the void back in the DOM indexer/no params case. Really trying to remove duplicates more than anything which is 98765.
-rw-r--r--core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java2
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsIndexAll.java10
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java2
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor2.java28
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProposal.java86
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProposalComparator.java7
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionContributor.java68
7 files changed, 132 insertions, 71 deletions
diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java
index 160b078b23..a2c683d866 100644
--- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java
+++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java
@@ -118,7 +118,7 @@ public class FunctionMethodPatternTests extends BaseSearchTest {
search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults();
- assertEquals( 0, matches.size()); // The pattern must match the use of the void in the code
+ assertEquals( 2, matches.size());
pattern = SearchEngine.createSearchPattern( "turnAgain()", METHOD, DECLARATIONS, true ); //$NON-NLS-1$
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsIndexAll.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsIndexAll.java
index 87777f87e3..1252cf38d8 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsIndexAll.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsIndexAll.java
@@ -237,16 +237,16 @@ class CTagsIndexAll extends CTagsIndexRequest {
}
Process p = launcher.execute(ctagsExecutable, args, null, directoryToRunFrom); //$NON-NLS-1$
+ if (p == null) {
+ //CTags not installed
+ indexer.createProblemMarker(CCorePlugin.getResourceString("CTagsIndexMarker.CTagsMissing"), project); //$NON-NLS-1$
+ return false;
+ }
p.waitFor();
} catch (InterruptedException e) {
return false;
}
- catch (NullPointerException e){
- //CTags not installed
- indexer.createProblemMarker(CCorePlugin.getResourceString("CTagsIndexMarker.CTagsMissing"), project); //$NON-NLS-1$
- return false;
- }
return true;
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java
index 1e5948d166..6d6dabc5cb 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java
@@ -221,6 +221,8 @@ public class IndexVisitorUtil {
}
if (function.takesVarArgs())
parameterList.add("...".toCharArray()); //$NON-NLS-1$
+ else if (parameters.length == 0)
+ parameterList.add("void".toCharArray()); //$NON-NLS-1$
}
catch (DOMException e) {
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor2.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor2.java
index 4de0ee555e..009f87f491 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor2.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor2.java
@@ -22,6 +22,7 @@ import org.eclipse.cdt.internal.ui.CUIMessages;
import org.eclipse.cdt.internal.ui.text.CParameterListValidator;
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.text.ICCompletionProposal;
import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -117,30 +118,39 @@ public class CCompletionProcessor2 implements IContentAssistProcessor {
}
}
- ICompletionProposal[] propsArray = null;
+ ICCompletionProposal[] propsArray = null;
if (!proposals.isEmpty()) {
errorMessage = null;
- propsArray = (ICompletionProposal[])proposals.toArray(new ICompletionProposal[proposals.size()]);
+ propsArray = (ICCompletionProposal[])proposals.toArray(new ICCompletionProposal[proposals.size()]);
CCompletionProposalComparator propsComp = new CCompletionProposalComparator();
propsComp.setOrderAlphabetically(true);
Arrays.sort(propsArray, propsComp);
- // remove duplicates
- ICompletionProposal last = propsArray[0];
+ // remove duplicates but leave the ones with return types
+
+ int last = 0;
int removed = 0;
for (int i = 1; i < propsArray.length; ++i) {
- if (propsComp.compare(last, propsArray[i]) == 0) {
- // Remove the duplicate
- ++removed;
+ if (propsComp.compare(propsArray[last], propsArray[i]) == 0) {
+ // We want to leave the one that has the return string if any
+ boolean lastReturn = propsArray[last].getIdString() != propsArray[last].getDisplayString();
+ boolean iReturn = propsArray[i].getIdString() != propsArray[i].getDisplayString();
+
+ if (!lastReturn && iReturn)
+ // flip i down to last
+ propsArray[last] = propsArray[i];
+
+ // Remove the duplicate
propsArray[i] = null;
+ ++removed;
} else
// update last
- last = propsArray[i];
+ last = i;
}
if (removed > 0) {
// Strip out the null entries
- ICompletionProposal[] newArray = new ICompletionProposal[propsArray.length - removed];
+ ICCompletionProposal[] newArray = new ICCompletionProposal[propsArray.length - removed];
int j = 0;
for (int i = 0; i < propsArray.length; ++i)
if (propsArray[i] != null)
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProposal.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProposal.java
index bd080669f0..09f3796792 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProposal.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProposal.java
@@ -55,6 +55,7 @@ import org.eclipse.ui.texteditor.link.EditorLinkedModeUI;
public class CCompletionProposal implements ICCompletionProposal, ICompletionProposalExtension, ICompletionProposalExtension2, ICompletionProposalExtension3 {
private String fDisplayString;
+ private String fIdString;
private String fReplacementString;
private int fReplacementOffset;
private int fReplacementLength;
@@ -81,39 +82,57 @@ public class CCompletionProposal implements ICCompletionProposal, ICompletionPro
* If set to <code>null</code>, the replacement string will be taken as display string.
*/
public CCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, String displayString, int relevance) {
- this(replacementString, replacementOffset, replacementLength, image, displayString, relevance, null);
- }
-
- /**
- * Creates a new completion proposal. All fields are initialized based on the provided information.
- *
- * @param replacementString the actual string to be inserted into the document
- * @param replacementOffset the offset of the text to be replaced
- * @param replacementLength the length of the text to be replaced
- * @param image the image to display for this proposal
- * @param displayString the string to be displayed for the proposal
- * @param viewer the text viewer for which this proposal is computed, may be <code>null</code>
- * If set to <code>null</code>, the replacement string will be taken as display string.
- */
- public CCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, String displayString, int relevance, ITextViewer viewer) {
- Assert.isNotNull(replacementString);
+ this(replacementString, replacementOffset, replacementLength, image, displayString, null, relevance, null);
+ }
+
+ /**
+ * Creates a new completion proposal. All fields are initialized based on the provided information.
+ *
+ * @param replacementString the actual string to be inserted into the document
+ * @param replacementOffset the offset of the text to be replaced
+ * @param replacementLength the length of the text to be replaced
+ * @param image the image to display for this proposal
+ * @param displayString the string to be displayed for the proposal
+ * @param viewer the text viewer for which this proposal is computed, may be <code>null</code>
+ * If set to <code>null</code>, the replacement string will be taken as display string.
+ */
+ public CCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, String displayString, int relevance, ITextViewer viewer) {
+ this(replacementString, replacementOffset, replacementLength, image, displayString, null, relevance, viewer);
+ }
+
+ /**
+ * Creates a new completion proposal. All fields are initialized based on the provided information.
+ *
+ * @param replacementString the actual string to be inserted into the document
+ * @param replacementOffset the offset of the text to be replaced
+ * @param replacementLength the length of the text to be replaced
+ * @param image the image to display for this proposal
+ * @param displayString the string to be displayed for the proposal
+ * @param idString the string to be uniquely identify this proposal
+ * @param viewer the text viewer for which this proposal is computed, may be <code>null</code>
+ * If set to <code>null</code>, the replacement string will be taken as display string.
+ */
+ public CCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, String displayString, String idString, int relevance, ITextViewer viewer) {
+ Assert.isNotNull(replacementString);
Assert.isTrue(replacementOffset >= 0);
Assert.isTrue(replacementLength >= 0);
- fReplacementString= replacementString;
- fReplacementOffset= replacementOffset;
- fReplacementLength= replacementLength;
- fImage= image;
- fDisplayString= displayString != null ? displayString : replacementString;
- fRelevance= relevance;
- fTextViewer= viewer;
-
- fCursorPosition= replacementString.length();
+ fReplacementString = replacementString;
+ fReplacementOffset = replacementOffset;
+ fReplacementLength = replacementLength;
+ fImage = image;
+ fRelevance = relevance;
+ fTextViewer = viewer;
+
+ fDisplayString = displayString != null ? displayString : replacementString;
+ fIdString = idString != null ? idString : displayString;
+
+ fCursorPosition = replacementString.length();
- fContextInformation= null;
- fContextInformationPosition= -1;
- fTriggerCharacters= null;
- fProposalInfo= null;
+ fContextInformation = null;
+ fContextInformationPosition = -1;
+ fTriggerCharacters = null;
+ fProposalInfo = null;
}
/**
@@ -339,6 +358,15 @@ public class CCompletionProposal implements ICCompletionProposal, ICompletionPro
return fDisplayString;
}
+ /**
+ * This method is used by the comparator to compare proposals. It ignores the return type of a function.
+ *
+ * @return the string representing the display name without the return type (if any).
+ */
+ public String getIdString() {
+ return fIdString;
+ }
+
/*
* @see ICompletionProposal#getAdditionalProposalInfo()
*/
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProposalComparator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProposalComparator.java
index 2048cc17bd..be7e69bbc8 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProposalComparator.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProposalComparator.java
@@ -36,13 +36,18 @@ public class CCompletionProposalComparator implements Comparator {
public int compare(Object o1, Object o2) {
ICCompletionProposal c1= (ICCompletionProposal) o1;
ICCompletionProposal c2= (ICCompletionProposal) o2;
+
if (!fOrderAlphabetically) {
int relevanceDif= c2.getRelevance() - c1.getRelevance();
if (relevanceDif != 0) {
return relevanceDif;
}
}
- return c1.getDisplayString().compareToIgnoreCase(c2.getDisplayString());
+
+ String id1 = c1.getIdString();
+ String id2 = c2.getIdString();
+
+ return id1.compareToIgnoreCase(id2);
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionContributor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionContributor.java
index c0ab071579..5ff561cf44 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionContributor.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionContributor.java
@@ -113,28 +113,35 @@ public class DOMCompletionContributor implements ICompletionContributor {
repStringBuff.append(function.getName());
repStringBuff.append('(');
- StringBuffer args = new StringBuffer();
+ StringBuffer dispargs = new StringBuffer(); // for the displayString
+ StringBuffer idargs = new StringBuffer(); // for the idString
String returnTypeStr = null;
try {
IParameter[] params = function.getParameters();
if (params != null)
for (int i = 0; i < params.length; ++i) {
IType paramType = params[i].getType();
- if (i > 0)
- args.append(',');
-
- args.append(ASTTypeUtil.getType(paramType));
+ if (i > 0) {
+ dispargs.append(',');
+ idargs.append(',');
+ }
+
+ dispargs.append(ASTTypeUtil.getType(paramType));
+ idargs.append(ASTTypeUtil.getType(paramType));
String paramName = params[i].getName();
if (paramName != null && paramName.length() > 0) {
- args.append(' ');
- args.append(paramName);
+ dispargs.append(' ');
+ dispargs.append(paramName);
}
}
if (function.takesVarArgs()) {
- if (args.length() > 0)
- args.append(',');
- args.append(" ..."); //$NON-NLS-1$
+ if (params.length > 0) {
+ dispargs.append(',');
+ idargs.append(',');
+ }
+ dispargs.append(" ..."); //$NON-NLS-1$
+ idargs.append(" ..."); //$NON-NLS-1$
}
IType returnType = function.getType().getReturnType();
@@ -142,26 +149,35 @@ public class DOMCompletionContributor implements ICompletionContributor {
returnTypeStr = ASTTypeUtil.getType(returnType);
} catch (DOMException e) {
}
- String argString = args.toString();
-
- StringBuffer descStringBuff = new StringBuffer(repStringBuff.toString());
- descStringBuff.append(argString);
- descStringBuff.append(')');
-
- if (returnTypeStr != null) {
- descStringBuff.append(' ');
- descStringBuff.append(returnTypeStr);
- }
+
+ String dispargString = dispargs.toString();
+ String idargString = idargs.toString();
- repStringBuff.append(')');
- String repString = repStringBuff.toString();
- String descString = descStringBuff.toString();
+ StringBuffer dispStringBuff = new StringBuffer(repStringBuff.toString());
+ dispStringBuff.append(dispargString);
+ dispStringBuff.append(')');
+ if (returnTypeStr != null) {
+ dispStringBuff.append(' ');
+ dispStringBuff.append(returnTypeStr);
+ }
+ String dispString = dispStringBuff.toString();
+
+ StringBuffer idStringBuff = new StringBuffer(repStringBuff.toString());
+ idStringBuff.append(idargString);
+ idStringBuff.append(')');
+ String idString = idStringBuff.toString();
- CCompletionProposal proposal = createProposal(repString, descString, image, completionNode, offset, viewer);
+ repStringBuff.append(')');
+ String repString = repStringBuff.toString();
+
+ int repLength = completionNode.getLength();
+ int repOffset = offset - repLength;
+ CCompletionProposal proposal = new CCompletionProposal(repString, repOffset, repLength, image, dispString, idString, 1, viewer);
+
proposal.setCursorPosition(repString.length() - 1);
- if (argString.length() > 0) {
- CProposalContextInformation info = new CProposalContextInformation(repString, argString);
+ if (dispargString.length() > 0) {
+ CProposalContextInformation info = new CProposalContextInformation(repString, dispargString);
info.setContextInformationPosition(offset);
proposal.setContextInformation(info);
}

Back to the top