mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Bug 509186 - Require an exact match for help proposals when providing context information
Change-Id: I06ccd65a0304921ebf2adbd556a89c8685237a8a
This commit is contained in:
parent
785b17a064
commit
24f099f882
3 changed files with 50 additions and 4 deletions
|
@ -59,10 +59,15 @@ public class CHelpProviderTester {
|
||||||
private class CHelpBook implements ICHelpBook {
|
private class CHelpBook implements ICHelpBook {
|
||||||
private int fCHelpType;
|
private int fCHelpType;
|
||||||
private String fTitle;
|
private String fTitle;
|
||||||
|
private List<IFunctionSummary> fFunctions = new ArrayList<>();
|
||||||
|
|
||||||
public CHelpBook(String providerID, int type) {
|
public CHelpBook(String providerID, int type) {
|
||||||
fCHelpType = 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
|
@Override
|
||||||
|
@ -74,6 +79,16 @@ public class CHelpProviderTester {
|
||||||
public int getCHelpType() {
|
public int getCHelpType() {
|
||||||
return fCHelpType;
|
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 {
|
private class CHelpResourceDescriptor implements ICHelpResourceDescriptor {
|
||||||
|
@ -272,11 +287,13 @@ public class CHelpProviderTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IFunctionSummary[] generateMatchingFunctions(ICHelpBook[] helpBooks, String prefix, String providerID) {
|
public IFunctionSummary[] generateMatchingFunctions(ICHelpBook[] helpBooks, String prefix, String providerID) {
|
||||||
IFunctionSummary sum[] = new IFunctionSummary[helpBooks.length];
|
ArrayList<IFunctionSummary> lst = new ArrayList<IFunctionSummary>();
|
||||||
for (int i = 0; i < helpBooks.length; i++) {
|
for (ICHelpBook helpBook : helpBooks) {
|
||||||
sum[i] = new FunctionSummary(helpBooks[i], prefix, providerID);
|
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) {
|
public ICHelpBook[] generateCHelpBooks(final String providerID) {
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.ui.tests.text.contentassist2;
|
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.core.testplugin.util.BaseTestCase;
|
||||||
import org.eclipse.cdt.ui.tests.chelp.CHelpTestInfoProvider;
|
import org.eclipse.cdt.ui.tests.chelp.CHelpTestInfoProvider;
|
||||||
|
|
||||||
|
@ -41,6 +43,10 @@ public class HelpProposalTests extends CompletionTestBase {
|
||||||
super.tearDown();
|
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() {
|
// int main() {
|
||||||
// setvbuf(file, NULL, _IOLBF, /*cursor*/);
|
// setvbuf(file, NULL, _IOLBF, /*cursor*/);
|
||||||
// }
|
// }
|
||||||
|
@ -53,4 +59,15 @@ public class HelpProposalTests extends CompletionTestBase {
|
||||||
assertEquals("", proposal.getReplacementString());
|
assertEquals("", proposal.getReplacementString());
|
||||||
assertNotNull(proposal.getContextInformation());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,9 +102,21 @@ public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
Image image = CUIPlugin.getImageDescriptorRegistry().get(
|
Image image = CUIPlugin.getImageDescriptorRegistry().get(
|
||||||
CElementImageProvider.getFunctionImageDescriptor());
|
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>();
|
List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
|
||||||
|
|
||||||
for (IFunctionSummary summary : summaries) {
|
for (IFunctionSummary summary : summaries) {
|
||||||
|
if (requireExactMatch && !summary.getName().equals(prefix)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
String fname = summary.getName() + "()"; //$NON-NLS-1$
|
String fname = summary.getName() + "()"; //$NON-NLS-1$
|
||||||
String fdesc = summary.getDescription();
|
String fdesc = summary.getDescription();
|
||||||
IFunctionSummary.IFunctionPrototypeSummary fproto = summary
|
IFunctionSummary.IFunctionPrototypeSummary fproto = summary
|
||||||
|
|
Loading…
Add table
Reference in a new issue