diff options
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 3b556e806d6..ce42ccdc0d3 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 045794f4fde..67e5fe7aa02 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 1d6ee992058..4be7afc935c 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 |