mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Content Assist work: Bug fixing
This commit is contained in:
parent
93369ee4cd
commit
4ae8242ff6
6 changed files with 169 additions and 30 deletions
|
@ -1,3 +1,7 @@
|
|||
2003-12-20 Hoda Amer
|
||||
- Fix for bug#44359: Content Assist: foo(void) does not require args to be filled
|
||||
- Fix for bug#44378: Content Assist: easy keyboard exit of argument-providing mode
|
||||
|
||||
2003-12-29 Hoda Amer
|
||||
- Added context checking for completions comming from contributions
|
||||
- Added preference : Show proposals in Alphabetical Order
|
||||
|
|
|
@ -117,9 +117,10 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
private SearchEngine searchEngine = null;
|
||||
private CSearchResultLabelProvider labelProvider = null;
|
||||
|
||||
private int currentOffset = 0;
|
||||
private IWorkingCopy currentSourceUnit = null;
|
||||
private int fCurrentOffset = 0;
|
||||
private IWorkingCopy fCurrentSourceUnit = null;
|
||||
private int fNumberOfComputedResults= 0;
|
||||
private ITextViewer fTextViewer;
|
||||
|
||||
public CCompletionProcessor(IEditorPart editor) {
|
||||
fEditor = (CEditor) editor;
|
||||
|
@ -369,16 +370,18 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
* Evaluate the actual proposals for C
|
||||
*/
|
||||
public ICCompletionProposal[] evalProposals(IDocument document, int documentOffset, IWorkingCopy unit, ITextViewer viewer) {
|
||||
// setup the global variables
|
||||
fCurrentOffset = documentOffset;
|
||||
fCurrentSourceUnit = unit;
|
||||
fTextViewer = viewer;
|
||||
|
||||
currentOffset = documentOffset;
|
||||
currentSourceUnit = unit;
|
||||
ArrayList completions = new ArrayList();
|
||||
|
||||
if (currentSourceUnit == null)
|
||||
if (fCurrentSourceUnit == null)
|
||||
return null;
|
||||
|
||||
// clear the completion list at the result collector
|
||||
resultCollector.reset();
|
||||
resultCollector.reset(viewer);
|
||||
|
||||
IASTCompletionNode completionNode = addProposalsFromModel(completions);
|
||||
addProposalsFromSearch(completionNode, completions);
|
||||
|
@ -412,7 +415,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
}
|
||||
try {
|
||||
fTemplateEngine[i].reset();
|
||||
fTemplateEngine[i].complete(viewer, currentOffset, null);
|
||||
fTemplateEngine[i].complete(viewer, fCurrentOffset, null);
|
||||
} catch (Exception x) {
|
||||
CUIPlugin.getDefault().log(x);
|
||||
}
|
||||
|
@ -425,7 +428,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
if(completionNode == null)
|
||||
return;
|
||||
String prefix = completionNode.getCompletionPrefix();
|
||||
int offset = currentOffset - prefix.length();
|
||||
int offset = fCurrentOffset - prefix.length();
|
||||
int length = prefix.length();
|
||||
|
||||
// calling functions should happen only within the context of a code body
|
||||
|
@ -451,7 +454,8 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
length,
|
||||
CPluginImages.get(CPluginImages.IMG_OBJS_FUNCTION),
|
||||
fproto.getPrototypeString(true),
|
||||
2);
|
||||
2,
|
||||
fTextViewer);
|
||||
|
||||
if(fdesc != null) {
|
||||
proposal.setAdditionalProposalInfo(fdesc);
|
||||
|
@ -482,7 +486,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
|
||||
private IASTCompletionNode addProposalsFromModel(List completions){
|
||||
//invoke the completion engine
|
||||
IASTCompletionNode completionNode = completionEngine.complete(currentSourceUnit, currentOffset);
|
||||
IASTCompletionNode completionNode = completionEngine.complete(fCurrentSourceUnit, fCurrentOffset);
|
||||
return completionNode;
|
||||
}
|
||||
|
||||
|
@ -490,7 +494,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
if(completionNode == null)
|
||||
return;
|
||||
String prefix = completionNode.getCompletionPrefix();
|
||||
int offset = currentOffset - prefix.length();
|
||||
int offset = fCurrentOffset - prefix.length();
|
||||
int length = prefix.length();
|
||||
|
||||
String searchPrefix = prefix + "*";
|
||||
|
@ -510,7 +514,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
List elementsFound = new LinkedList();
|
||||
|
||||
ICElement[] projectScopeElement = new ICElement[1];
|
||||
projectScopeElement[0] = (ICElement)currentSourceUnit.getCProject();
|
||||
projectScopeElement[0] = (ICElement)fCurrentSourceUnit.getCProject();
|
||||
scope = SearchEngine.createCSearchScope(projectScopeElement, projectScopeAndDependency);
|
||||
|
||||
// search for global variables, functions, classes, structs, unions, enums, macros, and namespaces
|
||||
|
|
|
@ -5,12 +5,17 @@ package org.eclipse.cdt.internal.ui.text.contentassist;
|
|||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.cdt.ui.text.*;
|
||||
import org.eclipse.cdt.internal.ui.text.link.LinkedPositionManager;
|
||||
import org.eclipse.cdt.internal.ui.text.link.LinkedPositionUI;
|
||||
import org.eclipse.cdt.internal.ui.text.link.LinkedPositionUI.ExitFlags;
|
||||
import org.eclipse.cdt.ui.text.ICCompletionProposal;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
|
||||
import org.eclipse.jface.text.contentassist.IContextInformation;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.swt.events.VerifyEvent;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
|
||||
|
@ -26,6 +31,7 @@ public class CCompletionProposal implements ICCompletionProposal, ICompletionPro
|
|||
private int fContextInformationPosition;
|
||||
//private IImportDeclaration fImportDeclaration;
|
||||
private char[] fTriggerCharacters;
|
||||
protected ITextViewer fTextViewer;
|
||||
|
||||
private int fRelevance;
|
||||
|
||||
|
@ -39,7 +45,7 @@ public class CCompletionProposal implements ICCompletionProposal, ICompletionPro
|
|||
* @param displayString the string to be displayed for the proposal
|
||||
* If set to <code>null</code>, the replacement string will be taken as display string.
|
||||
*/
|
||||
public CCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, String displayString, int relevance) {
|
||||
public CCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, String displayString, int relevance, ITextViewer viewer) {
|
||||
Assert.isNotNull(replacementString);
|
||||
Assert.isTrue(replacementOffset >= 0);
|
||||
Assert.isTrue(replacementLength >= 0);
|
||||
|
@ -50,6 +56,7 @@ public class CCompletionProposal implements ICCompletionProposal, ICompletionPro
|
|||
fImage= image;
|
||||
fDisplayString= displayString != null ? displayString : replacementString;
|
||||
fRelevance= relevance;
|
||||
fTextViewer= viewer;
|
||||
|
||||
//@@@ Is this the best way to do this, likely it isn't
|
||||
if(replacementString.indexOf("()") == -1) { //Not replacing with a function
|
||||
|
@ -185,7 +192,9 @@ public class CCompletionProposal implements ICCompletionProposal, ICompletionPro
|
|||
}
|
||||
|
||||
try {
|
||||
String string;
|
||||
if (trigger == (char) 0) {
|
||||
string= fReplacementString;
|
||||
replace(document, fReplacementOffset, fReplacementLength, replacementStringCopy);
|
||||
} else {
|
||||
StringBuffer buffer= new StringBuffer(replacementStringCopy);
|
||||
|
@ -196,7 +205,26 @@ public class CCompletionProposal implements ICCompletionProposal, ICompletionPro
|
|||
++fCursorPosition;
|
||||
}
|
||||
|
||||
replace(document, fReplacementOffset, fReplacementLength, buffer.toString());
|
||||
string= buffer.toString();
|
||||
replace(document, fReplacementOffset, fReplacementLength, string);
|
||||
}
|
||||
|
||||
if (fTextViewer != null && string != null) {
|
||||
int index= string.indexOf("()"); //$NON-NLS-1$
|
||||
if (index != -1 && index + 1 == fCursorPosition) {
|
||||
//IPreferenceStore preferenceStore= JavaPlugin.getDefault().getPreferenceStore();
|
||||
//if (preferenceStore.getBoolean(PreferenceConstants.EDITOR_CLOSE_BRACKETS)) {
|
||||
int newOffset= fReplacementOffset + fCursorPosition;
|
||||
|
||||
LinkedPositionManager manager= new LinkedPositionManager(document);
|
||||
manager.addPosition(newOffset, 0);
|
||||
|
||||
LinkedPositionUI editor= new LinkedPositionUI(fTextViewer, manager);
|
||||
editor.setExitPolicy(new ExitPolicy(')'));
|
||||
editor.setFinalCaretOffset(newOffset + 1);
|
||||
editor.enter();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -397,5 +425,44 @@ public class CCompletionProposal implements ICCompletionProposal, ICompletionPro
|
|||
return true;
|
||||
}
|
||||
|
||||
private static class ExitPolicy implements LinkedPositionUI.ExitPolicy {
|
||||
|
||||
final char fExitCharacter;
|
||||
|
||||
public ExitPolicy(char exitCharacter) {
|
||||
fExitCharacter= exitCharacter;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jdt.internal.ui.text.link.LinkedPositionUI.ExitPolicy#doExit(org.eclipse.jdt.internal.ui.text.link.LinkedPositionManager, org.eclipse.swt.events.VerifyEvent, int, int)
|
||||
*/
|
||||
public ExitFlags doExit(LinkedPositionManager manager, VerifyEvent event, int offset, int length) {
|
||||
|
||||
if (event.character == fExitCharacter) {
|
||||
if (manager.anyPositionIncludes(offset, length))
|
||||
return new ExitFlags(LinkedPositionUI.COMMIT| LinkedPositionUI.UPDATE_CARET, false);
|
||||
else
|
||||
return new ExitFlags(LinkedPositionUI.COMMIT, true);
|
||||
}
|
||||
|
||||
switch (event.character) {
|
||||
case '\b':
|
||||
if (manager.getFirstPosition().length == 0)
|
||||
return new ExitFlags(0, true);
|
||||
else
|
||||
return null;
|
||||
|
||||
case '\n':
|
||||
case '\r':
|
||||
case ';':
|
||||
return new ExitFlags(LinkedPositionUI.COMMIT, true);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
|
|||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.FunctionPrototypeSummary;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.contentassist.ContextInformation;
|
||||
import org.eclipse.jface.text.contentassist.ICompletionProposal;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
@ -36,9 +37,11 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
private Set completions = new HashSet();
|
||||
private ImageDescriptorRegistry registry = CUIPlugin.getImageDescriptorRegistry();
|
||||
private IProblem fLastProblem;
|
||||
private ITextViewer fTextViewer;
|
||||
|
||||
public ResultCollector(){
|
||||
completions.clear();
|
||||
fTextViewer = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,8 +50,9 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
public Set getCompletions() {
|
||||
return completions;
|
||||
}
|
||||
public void reset() {
|
||||
public void reset(ITextViewer viewer) {
|
||||
completions.clear();
|
||||
fTextViewer = viewer;
|
||||
fLastProblem = null;
|
||||
}
|
||||
/*
|
||||
|
@ -63,8 +67,8 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
length,
|
||||
image,
|
||||
displayString, // Display string
|
||||
relevance
|
||||
);
|
||||
relevance,
|
||||
fTextViewer);
|
||||
|
||||
if(arguments != null && arguments.length() > 0) {
|
||||
proposal.setContextInformation(new ContextInformation(replaceString, arguments));
|
||||
|
@ -152,8 +156,15 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
replaceString = name;
|
||||
displayString = name;
|
||||
String functionPrototype = returnType + " " + name;
|
||||
if(parameterString != null)
|
||||
if(parameterString != null){
|
||||
if ((parameterString.indexOf("(") == -1) && (parameterString.indexOf(")") == -1))
|
||||
{
|
||||
functionPrototype += "(" + parameterString + ")";
|
||||
}
|
||||
else {
|
||||
functionPrototype += parameterString;
|
||||
}
|
||||
}
|
||||
|
||||
FunctionPrototypeSummary fproto = new FunctionPrototypeSummary(functionPrototype);
|
||||
if(fproto != null) {
|
||||
|
@ -253,8 +264,15 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
replaceString = name;
|
||||
displayString = name;
|
||||
String functionPrototype = returnType + " " + name;
|
||||
if(parameterString != null)
|
||||
if(parameterString != null){
|
||||
if ((parameterString.indexOf("(") != -1) && (parameterString.indexOf(")") != -1))
|
||||
{
|
||||
functionPrototype += "(" + parameterString + ")";
|
||||
}
|
||||
else {
|
||||
functionPrototype += parameterString;
|
||||
}
|
||||
}
|
||||
|
||||
FunctionPrototypeSummary fproto = new FunctionPrototypeSummary(functionPrototype);
|
||||
if(fproto != null) {
|
||||
|
|
|
@ -57,9 +57,9 @@ public class LinkedPositionUI implements LinkedPositionListener,
|
|||
|
||||
// leave flags
|
||||
private static final int UNINSTALL= 1; // uninstall linked position manager
|
||||
private static final int COMMIT= 2; // commit changes
|
||||
public static final int COMMIT= 2; // commit changes
|
||||
private static final int DOCUMENT_CHANGED= 4; // document has changed
|
||||
private static final int UPDATE_CARET= 8; // update caret
|
||||
public static final int UPDATE_CARET= 8; // update caret
|
||||
|
||||
private static final String CARET_POSITION= "LinkedPositionUI.caret.position";
|
||||
private static final IPositionUpdater fgUpdater= new DefaultPositionUpdater(CARET_POSITION);
|
||||
|
@ -74,6 +74,7 @@ public class LinkedPositionUI implements LinkedPositionListener,
|
|||
private Position fFramePosition;
|
||||
private int fCaretOffset;
|
||||
|
||||
private ExitPolicy fExitPolicy;
|
||||
private ExitListener fExitListener;
|
||||
|
||||
/**
|
||||
|
@ -165,7 +166,13 @@ public class LinkedPositionUI implements LinkedPositionListener,
|
|||
|
||||
fCaretOffset= caretOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an <code>ExitPolicy</code> which decides when and how
|
||||
* the linked mode is exited.
|
||||
*/
|
||||
public void setExitPolicy(ExitPolicy policy) {
|
||||
fExitPolicy= policy;
|
||||
}
|
||||
/**
|
||||
* Enters the linked mode. The linked mode can be left by calling
|
||||
* <code>exit</code>.
|
||||
|
@ -309,14 +316,28 @@ public class LinkedPositionUI implements LinkedPositionListener,
|
|||
* @see VerifyKeyListener#verifyKey(VerifyEvent)
|
||||
*/
|
||||
public void verifyKey(VerifyEvent event) {
|
||||
if (!event.doit )
|
||||
return;
|
||||
|
||||
Point selection= fViewer.getSelectedRange();
|
||||
int offset= selection.x;
|
||||
int length= selection.y;
|
||||
|
||||
ExitFlags exitFlags= fExitPolicy == null ? null : fExitPolicy.doExit(fManager, event, offset, length);
|
||||
if (exitFlags != null) {
|
||||
leave(UNINSTALL | exitFlags.flags);
|
||||
event.doit= exitFlags.doit;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.character) {
|
||||
// [SHIFT-]TAB = hop between edit boxes
|
||||
case 0x09:
|
||||
{
|
||||
Point selection= fViewer.getTextWidget().getSelection();
|
||||
selection= fViewer.getTextWidget().getSelection();
|
||||
IRegion region= fViewer.getVisibleRegion();
|
||||
int offset= selection.x + region.getOffset();
|
||||
int length= selection.y - selection.x;
|
||||
offset= selection.x + region.getOffset();
|
||||
length= selection.y - selection.x;
|
||||
|
||||
// if tab was treated as a document change, would it exceed variable range?
|
||||
if (!LinkedPositionManager.includes(fFramePosition, offset, length)) {
|
||||
|
@ -344,6 +365,12 @@ public class LinkedPositionUI implements LinkedPositionListener,
|
|||
leave(UNINSTALL | COMMIT);
|
||||
event.doit= false;
|
||||
break;
|
||||
|
||||
case ';':
|
||||
leave(UNINSTALL | COMMIT);
|
||||
event.doit= true;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -502,4 +529,19 @@ public class LinkedPositionUI implements LinkedPositionListener,
|
|||
position.getOffset() >= region.getOffset() &&
|
||||
position.getOffset() + position.getLength() <= region.getOffset() + region.getLength();
|
||||
}
|
||||
|
||||
|
||||
public static class ExitFlags {
|
||||
public int flags;
|
||||
public boolean doit;
|
||||
public ExitFlags(int flags, boolean doit) {
|
||||
this.flags= flags;
|
||||
this.doit= doit;
|
||||
}
|
||||
}
|
||||
|
||||
public interface ExitPolicy {
|
||||
ExitFlags doExit(LinkedPositionManager manager, VerifyEvent event, int offset, int length);
|
||||
}
|
||||
|
||||
}
|
|
@ -38,6 +38,10 @@ public class FunctionPrototypeSummary implements IFunctionSummary.IFunctionProto
|
|||
|
||||
farguments = proto.substring(leftbracket + 1, rightbracket);
|
||||
|
||||
// fix for bug #44359
|
||||
if(farguments.equals("void"))
|
||||
farguments = "";
|
||||
|
||||
int nameend = leftbracket - 1;
|
||||
while(proto.charAt(nameend) == ' ') {
|
||||
nameend--;
|
||||
|
|
Loading…
Add table
Reference in a new issue