mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-30 21:55:31 +02:00
Adding handler for formatting variable completion proposals (see bug #129768)
This commit is contained in:
parent
373957fc6f
commit
0785646dcc
1 changed files with 37 additions and 1 deletions
|
@ -94,8 +94,11 @@ public class DOMCompletionContributor implements ICompletionContributor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleBinding(IBinding binding, ASTCompletionNode completionNode, int offset, ITextViewer viewer, List proposals) {
|
private void handleBinding(IBinding binding, ASTCompletionNode completionNode, int offset, ITextViewer viewer, List proposals) {
|
||||||
if (binding instanceof IFunction)
|
if (binding instanceof IFunction) {
|
||||||
handleFunction((IFunction)binding, completionNode, offset, viewer, proposals);
|
handleFunction((IFunction)binding, completionNode, offset, viewer, proposals);
|
||||||
|
} else if (binding instanceof IVariable) {
|
||||||
|
handleVariable((IVariable) binding, completionNode, offset, viewer, proposals);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
proposals.add(createProposal(binding.getName(), binding.getName(), getImage(binding), completionNode, offset, viewer));
|
proposals.add(createProposal(binding.getName(), binding.getName(), getImage(binding), completionNode, offset, viewer));
|
||||||
}
|
}
|
||||||
|
@ -182,6 +185,39 @@ public class DOMCompletionContributor implements ICompletionContributor {
|
||||||
proposals.add(proposal);
|
proposals.add(proposal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleVariable(IVariable variable, ASTCompletionNode completionNode, int offset, ITextViewer viewer, List proposals) {
|
||||||
|
StringBuffer repStringBuff = new StringBuffer();
|
||||||
|
repStringBuff.append(variable.getName());
|
||||||
|
|
||||||
|
String returnTypeStr = "<unknown>";
|
||||||
|
try {
|
||||||
|
IType varType = variable.getType();
|
||||||
|
if (varType != null)
|
||||||
|
returnTypeStr = ASTTypeUtil.getType(varType);
|
||||||
|
} catch (DOMException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuffer dispStringBuff = new StringBuffer(repStringBuff.toString());
|
||||||
|
if (returnTypeStr != null) {
|
||||||
|
dispStringBuff.append(" : ");
|
||||||
|
dispStringBuff.append(returnTypeStr);
|
||||||
|
}
|
||||||
|
String dispString = dispStringBuff.toString();
|
||||||
|
|
||||||
|
StringBuffer idStringBuff = new StringBuffer(repStringBuff.toString());
|
||||||
|
String idString = idStringBuff.toString();
|
||||||
|
|
||||||
|
String repString = repStringBuff.toString();
|
||||||
|
|
||||||
|
int repLength = completionNode.getLength();
|
||||||
|
int repOffset = offset - repLength;
|
||||||
|
CCompletionProposal proposal = new CCompletionProposal(repString, repOffset, repLength, null, dispString, idString, 1, viewer);
|
||||||
|
|
||||||
|
proposal.setCursorPosition(repString.length() - 1);
|
||||||
|
|
||||||
|
proposals.add(proposal);
|
||||||
|
}
|
||||||
|
|
||||||
private void handleMacro(IASTPreprocessorMacroDefinition macro, ASTCompletionNode completionNode, int offset, ITextViewer viewer, List proposals) {
|
private void handleMacro(IASTPreprocessorMacroDefinition macro, ASTCompletionNode completionNode, int offset, ITextViewer viewer, List proposals) {
|
||||||
String macroName = macro.getName().toString();
|
String macroName = macro.getName().toString();
|
||||||
Image image = getImage(CElementImageProvider.getMacroImageDescriptor());
|
Image image = getImage(CElementImageProvider.getMacroImageDescriptor());
|
||||||
|
|
Loading…
Add table
Reference in a new issue