1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Bug 509186 - Require an exact match for help proposals when providing context information

Change-Id: I06ccd65a0304921ebf2adbd556a89c8685237a8a
This commit is contained in:
Nathan Ridge 2017-01-12 01:38:51 -05:00
parent 785b17a064
commit 24f099f882
3 changed files with 50 additions and 4 deletions

View file

@ -59,10 +59,15 @@ public class CHelpProviderTester {
private class CHelpBook implements ICHelpBook {
private int fCHelpType;
private String fTitle;
private List<IFunctionSummary> fFunctions = new ArrayList<>();
public CHelpBook(String providerID, int type) {
fCHelpType = 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
@ -74,6 +79,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 {
@ -272,11 +287,13 @@ public class CHelpProviderTester {
}
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);
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) {

View file

@ -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);
}
}

View file

@ -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