Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2017-01-12 01:38:51 -0500
committerNathan Ridge2017-01-25 19:03:49 -0500
commit1b164b5d8740099e27e780b67d547cceb45d1b13 (patch)
tree487bffb0736c0699e9d17479ebd710de3dace55a
parent07ca5174d52599810a7d1b029749058b9dd1a5ba (diff)
downloadorg.eclipse.cdt-1b164b5d8740099e27e780b67d547cceb45d1b13.tar.gz
org.eclipse.cdt-1b164b5d8740099e27e780b67d547cceb45d1b13.tar.xz
org.eclipse.cdt-1b164b5d8740099e27e780b67d547cceb45d1b13.zip
Bug 509186 - Require an exact match for help proposals when providing context information
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/chelp/CHelpProviderTester.java35
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/HelpProposalTests.java17
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionProposalComputer.java12
3 files changed, 55 insertions, 9 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/chelp/CHelpProviderTester.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/chelp/CHelpProviderTester.java
index 3b556e806d..ce42ccdc0d 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/chelp/CHelpProviderTester.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/chelp/CHelpProviderTester.java
@@ -56,10 +56,15 @@ public class CHelpProviderTester{
private class CHelpBook implements ICHelpBook{
private int fCHelpType;
private String fTitle;
-
- public CHelpBook(String providerID, int type){
+ private List<IFunctionSummary> fFunctions = new ArrayList<>();
+
+ public CHelpBook(String providerID, int type) {
fCHelpType = type;
- fTitle = generateBookTitle(providerID,type);
+ fTitle = generateBookTitle(providerID, type);
+ if (fCHelpType == HELP_TYPE_C) {
+ fFunctions.add(new FunctionSummary(this, "setvbuf", providerID));
+ fFunctions.add(new FunctionSummary(this, "wait", providerID));
+ }
}
@Override
@@ -71,6 +76,16 @@ public class CHelpProviderTester{
public int getCHelpType(){
return fCHelpType;
}
+
+ public List<IFunctionSummary> getMatchingFunctions(String prefix) {
+ List<IFunctionSummary> result = new ArrayList<>();
+ for (IFunctionSummary function : fFunctions) {
+ if (function.getName().startsWith(prefix)) {
+ result.add(function);
+ }
+ }
+ return result;
+ }
}
private class CHelpResourceDescriptor implements ICHelpResourceDescriptor{
@@ -257,13 +272,15 @@ public class CHelpProviderTester{
return null;
return new FunctionSummary(helpBooks[0],name,providerID);
}
-
- public IFunctionSummary[] generateMatchingFunctions(ICHelpBook[] helpBooks, String prefix, String providerID){
- IFunctionSummary sum[] = new IFunctionSummary[helpBooks.length];
- for(int i = 0; i < helpBooks.length; i++){
- sum[i] = new FunctionSummary(helpBooks[i],prefix,providerID);
+
+ public IFunctionSummary[] generateMatchingFunctions(ICHelpBook[] helpBooks, String prefix, String providerID) {
+ ArrayList<IFunctionSummary> lst = new ArrayList<IFunctionSummary>();
+ for (ICHelpBook helpBook : helpBooks) {
+ if (helpBook instanceof CHelpBook) {
+ lst.addAll(((CHelpBook) helpBook).getMatchingFunctions(prefix));
+ }
}
- return sum;
+ return lst.toArray(new IFunctionSummary[lst.size()]);
}
public ICHelpBook[] generateCHelpBooks(final String providerID){
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/HelpProposalTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/HelpProposalTests.java
index 045794f4fd..67e5fe7aa0 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/HelpProposalTests.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/HelpProposalTests.java
@@ -7,6 +7,8 @@
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
+import static org.eclipse.cdt.ui.tests.text.contentassist2.AbstractContentAssistTest.CompareType.ID;
+
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.ui.tests.chelp.CHelpTestInfoProvider;
@@ -41,6 +43,10 @@ public class HelpProposalTests extends CompletionTestBase {
super.tearDown();
}
+ // Note: The help proposal completions for C library functions that are proposed
+ // in this test are defined in the CHelpProposalTester.CHelpBook constructor.
+ // When writing a new test case, add any necessary new functions there.
+
// int main() {
// setvbuf(file, NULL, _IOLBF, /*cursor*/);
// }
@@ -53,4 +59,15 @@ public class HelpProposalTests extends CompletionTestBase {
assertEquals("", proposal.getReplacementString());
assertNotNull(proposal.getContextInformation());
}
+
+ // struct Waldo {
+ // Waldo(int, int);
+ // };
+ // int main() {
+ // Waldo w(/*cursor*/
+ // }
+ public void testHelpProposalInInappropriateContext_509186() throws Exception {
+ String[] expected = new String[] { "Waldo(const Waldo &)", "Waldo(int, int)" };
+ assertCompletionResults(fCursorOffset, expected, ID);
+ }
}
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
index 1d6ee99205..4be7afc935 100644
--- 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
@@ -102,9 +102,21 @@ public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer
Image image = CUIPlugin.getImageDescriptorRegistry().get(
CElementImageProvider.getFunctionImageDescriptor());
+ // If we are only providing context information, "prefix" is a complete
+ // function name, and we only want functions matching it exactly as
+ // proposals.
+ // TODO: It would be more efficient to expose this flag in
+ // IContentAssistHelpInvocationContext and have the help providers
+ // not generate prefix matches to begin with if it's set.
+ boolean requireExactMatch = cContext.isContextInformationStyle();
+
List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
for (IFunctionSummary summary : summaries) {
+ if (requireExactMatch && !summary.getName().equals(prefix)) {
+ continue;
+ }
+
String fname = summary.getName() + "()"; //$NON-NLS-1$
String fdesc = summary.getDescription();
IFunctionSummary.IFunctionPrototypeSummary fproto = summary

Back to the top