mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-11 18:25:40 +02:00
Bug 98881 - Added lots of goodies to the search completion to make it more usable.
This commit is contained in:
parent
4a917f5a73
commit
727f454fa7
2 changed files with 83 additions and 16 deletions
|
@ -30,6 +30,20 @@ public interface IMatch {
|
||||||
|
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of parameters if this matched a function or a method.
|
||||||
|
*
|
||||||
|
* @return array of Strings for the parameters
|
||||||
|
*/
|
||||||
|
String[] getParameters();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the return type if this matched a function or a method.
|
||||||
|
*
|
||||||
|
* @return the return type
|
||||||
|
*/
|
||||||
|
String getReturnType();
|
||||||
|
|
||||||
String getParentName();
|
String getParentName();
|
||||||
|
|
||||||
IResource getResource();
|
IResource getResource();
|
||||||
|
|
|
@ -15,15 +15,16 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
|
||||||
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
|
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
|
||||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||||
|
import org.eclipse.cdt.core.search.IMatch;
|
||||||
import org.eclipse.cdt.core.search.SearchEngine;
|
import org.eclipse.cdt.core.search.SearchEngine;
|
||||||
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
|
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
@ -50,7 +51,7 @@ public class SearchCompletionContributor implements ICompletionContributor {
|
||||||
ICSearchScope scope = SearchEngine.createWorkspaceScope();
|
ICSearchScope scope = SearchEngine.createWorkspaceScope();
|
||||||
|
|
||||||
// Create the pattern
|
// Create the pattern
|
||||||
ICSearchPattern pattern = SearchEngine.createSearchPattern(prefix + "*", ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, false); //$NON-NLS-1$
|
ICSearchPattern pattern = SearchEngine.createSearchPattern(prefix + "*", ICSearchConstants.UNKNOWN_SEARCH_FOR, ICSearchConstants.ALL_OCCURRENCES, false); //$NON-NLS-1$
|
||||||
|
|
||||||
// Run the search
|
// Run the search
|
||||||
BasicSearchResultCollector collector = new BasicSearchResultCollector();
|
BasicSearchResultCollector collector = new BasicSearchResultCollector();
|
||||||
|
@ -63,8 +64,17 @@ public class SearchCompletionContributor implements ICompletionContributor {
|
||||||
Set results = collector.getSearchResults();
|
Set results = collector.getSearchResults();
|
||||||
Iterator iResults = results.iterator();
|
Iterator iResults = results.iterator();
|
||||||
while (iResults.hasNext()) {
|
while (iResults.hasNext()) {
|
||||||
BasicSearchMatch match = (BasicSearchMatch)iResults.next();
|
IMatch match = (IMatch)iResults.next();
|
||||||
handleFunction(match.getName(), viewer, prefix, offset, proposals);
|
switch (match.getElementType()) {
|
||||||
|
case ICElement.C_FUNCTION:
|
||||||
|
case ICElement.C_FUNCTION_DECLARATION:
|
||||||
|
case ICElement.C_METHOD:
|
||||||
|
case ICElement.C_METHOD_DECLARATION:
|
||||||
|
handleFunction(match, viewer, prefix, offset, proposals);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
handleMatch(match, viewer, prefix, offset, proposals);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,14 +106,57 @@ public class SearchCompletionContributor implements ICompletionContributor {
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleFunction(String name, ITextViewer viewer, String prefix, int offset, List proposals) {
|
private void handleMatch(IMatch match, ITextViewer viewer, String prefix, int offset, List proposals) {
|
||||||
int repLength = prefix.length();
|
int repLength = prefix.length();
|
||||||
int repOffset = offset - repLength;
|
int repOffset = offset - repLength;
|
||||||
Image image = CUIPlugin.getImageDescriptorRegistry().get(CElementImageProvider.getFunctionImageDescriptor());
|
Image image = CUIPlugin.getImageDescriptorRegistry().get(CElementImageProvider.getImageDescriptor(match.getElementType()));
|
||||||
String repString = name + "()"; //$NON-NLS-1$
|
String repString = match.getName();
|
||||||
CCompletionProposal proposal = new CCompletionProposal(repString, repOffset, repLength, image, repString, 1, viewer);
|
CCompletionProposal proposal = new CCompletionProposal(repString, repOffset, repLength, image, repString, 1, viewer);
|
||||||
proposal.setCursorPosition(repString.length() - 1);
|
proposals.add(proposal);
|
||||||
proposals.add(proposal);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
private void handleFunction(IMatch match, ITextViewer viewer, String prefix, int offset, List proposals) {
|
||||||
|
Image image = CUIPlugin.getImageDescriptorRegistry().get(CElementImageProvider.getImageDescriptor(match.getElementType()));
|
||||||
|
|
||||||
|
StringBuffer repStringBuff = new StringBuffer();
|
||||||
|
repStringBuff.append(match.getName());
|
||||||
|
repStringBuff.append('(');
|
||||||
|
|
||||||
|
StringBuffer args = new StringBuffer();
|
||||||
|
String[] params = match.getParameters();
|
||||||
|
if (params != null)
|
||||||
|
for (int i = 0; i < params.length; ++i) {
|
||||||
|
if (i > 0)
|
||||||
|
args.append(", "); //$NON-NLS-1$
|
||||||
|
args.append(params[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
String returnType = match.getReturnType();
|
||||||
|
String argString = args.toString();
|
||||||
|
|
||||||
|
StringBuffer descStringBuff = new StringBuffer(repStringBuff.toString());
|
||||||
|
descStringBuff.append(argString);
|
||||||
|
descStringBuff.append(')');
|
||||||
|
|
||||||
|
if (returnType != null) {
|
||||||
|
descStringBuff.append(' ');
|
||||||
|
descStringBuff.append(returnType);
|
||||||
|
}
|
||||||
|
|
||||||
|
repStringBuff.append(')');
|
||||||
|
String repString = repStringBuff.toString();
|
||||||
|
String descString = descStringBuff.toString();
|
||||||
|
|
||||||
|
int repLength = prefix.length();
|
||||||
|
int repOffset = offset - repLength;
|
||||||
|
CCompletionProposal proposal = new CCompletionProposal(repString, repOffset, repLength, image, descString, 1, viewer);
|
||||||
|
proposal.setCursorPosition(repString.length() - 1);
|
||||||
|
|
||||||
|
if (argString.length() > 0) {
|
||||||
|
CProposalContextInformation info = new CProposalContextInformation(repString, argString);
|
||||||
|
info.setContextInformationPosition(offset);
|
||||||
|
proposal.setContextInformation(info);
|
||||||
|
}
|
||||||
|
proposals.add(proposal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue