Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Cursor positioning patch

This patch addresses the issues I found with the new code completion
where the bracket positioning wasn't performed on functions and 
methods which also meant that the proper argument highlighting didn't
occur.

For the ChangeLog:

 Update code completion to include () for functions and methods and
 to position the cursor appropriately.



Index: src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java,v
retrieving revision 1.9
diff -u -r1.9 CCompletionProcessor.java
--- src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java	12 Aug 2003 20:20:12 -0000	1.9
+++ src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java	26 Aug 2003 13:43:06 -0000
@@ -15,7 +15,6 @@
 import org.eclipse.cdt.core.index.TagFlags;
 import org.eclipse.cdt.core.model.CoreModel;
 import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.core.model.IField;
 import org.eclipse.cdt.core.model.IFunction;
 import org.eclipse.cdt.core.model.IFunctionDeclaration;
 import org.eclipse.cdt.core.model.IMember;
@@ -591,31 +590,36 @@
 		Iterator i = elementsFound.iterator();
 		while (i.hasNext()){
 			CCompletionProposal proposal;
-			FunctionPrototypeSummary fproto = null;
-			String fname = "";
+			String replaceString = "";
 			String displayString = "";
 			Image image = null;
 			StringBuffer infoString = new StringBuffer();
 			
 			BasicSearchMatch match = (BasicSearchMatch)i.next();
-			fproto = getPrototype(match);						
-			fname = (fproto == null) ? match.getName() : fproto.getName();
-			displayString = (fproto == null) ? fname : fproto.getPrototypeString(true);
+
+			//Make sure we replace with the appropriate string for functions and methods
+			FunctionPrototypeSummary fproto = getPrototype(match);
+			if(fproto != null) {						
+				replaceString = fproto.getName() + "()";
+				displayString = fproto.getPrototypeString(true);
+			} else {
+				replaceString = 
+				displayString = match.getName();;
+			}
+
 			image = labelProvider.getImage(match);
 			infoString.append(displayString);
 			if(match.getParentName().length() > 0) {
 				infoString.append(" - Parent: ");
 				infoString.append(match.getParentName());
 			}							 
-			
-			
 			 
 			proposal = new CCompletionProposal(
-												fname, // replacement string
+												replaceString, // Replacement string
 											   	region.getOffset(), 
 											   	region.getLength(),
 											   	image,
-											   	displayString, // displayString
+											   	displayString, // Display string
 											   	calculateRelevance(match)
 											  );
 			completions.add(proposal);
@@ -625,7 +629,7 @@
 			if(fproto != null){
 				String fargs = fproto.getArguments();
 				if(fargs != null && fargs.length() > 0) {
-					proposal.setContextInformation(new ContextInformation(fname, fargs));
+					proposal.setContextInformation(new ContextInformation(replaceString, fargs));
 				}
 			}
 			
@@ -642,42 +646,61 @@
 		ITagEntry[] tags = model.query(project, frag + "*", false, false);
 		if (tags != null && tags.length > 0) {
 			for (int i = 0; i < tags.length; i++) {
-				String fname = tags[i].getTagName();
 				FunctionPrototypeSummary fproto = null;
+				String fargs = null;
+				String fdisplay = null;
+				String fdesc = null;
+				String fname = tags[i].getTagName();
 				int kind = tags[i].getKind();
 
+				//No member completion yet
+				if (kind == TagFlags.T_MEMBER) {
+					continue;
+				}
+
+				//This doesn't give you a nice "function" look to macros, but is safe
 				if (kind == TagFlags.T_FUNCTION || kind == TagFlags.T_PROTOTYPE) {
 					fname = fname + "()";
-				}
-				
-				if(tags[i].getPattern() != null) {
-					try {
-						fproto = new FunctionPrototypeSummary(tags[i].getPattern());
-					} catch(Exception ex) {
-						fproto = null;
+
+					String pattern = tags[i].getPattern();
+					if(pattern != null) {
+						fproto = new FunctionPrototypeSummary(pattern);
+					} 				
+		
+					if(fproto == null) {
+						fproto = new FunctionPrototypeSummary(fname);
 					}
-				} 				
-				if(fproto == null) {
-					fproto = new FunctionPrototypeSummary(fname);
+				} 
+				
+				if(fproto != null) {
+					fargs = fproto.getArguments();
+					fdisplay = fproto.getPrototypeString(true);
+				} else {
+					fdisplay = fname;
 				}
 
+				//@@@ In the future something more usefull could go in here (ie Doxygen/JavaDoc)
+				fdesc = "<b>" + fname + "</b><br>" + "Defined in:<br> " + tags[i].getFileName();
+				if(tags[i].getClassName() != null) {
+					fdesc = fdesc + "<br>Class:<br> " + tags[i].getClassName(); 
+				}
+				    
 				//System.out.println("tagmatch " + fname + " proto " + proto + " type" + tags[i].getKind());
-				if (kind != TagFlags.T_MEMBER) {
-					CCompletionProposal proposal;
-					proposal = new CCompletionProposal(fname, 
-													   region.getOffset(), 
-													   region.getLength(),
-													   getTagImage(kind), 
-													   fproto.getPrototypeString(true),
-													   3);
-					completions.add(proposal);
-
-					//No summary information available yet
-
-					String fargs = fproto.getArguments();
-					if(fargs != null && fargs.length() > 0) {
-						proposal.setContextInformation(new ContextInformation(fname, fargs));
-					}
+				CCompletionProposal proposal;
+				proposal = new CCompletionProposal(fname, 
+												   region.getOffset(), 
+												   region.getLength(),
+												   getTagImage(kind), 
+												   fdisplay,
+												   3);
+				completions.add(proposal);
+
+				if(fdesc != null) {
+					proposal.setAdditionalProposalInfo(fdesc);
+				}
+				
+				if(fargs != null && fargs.length() > 0) {
+					proposal.setContextInformation(new ContextInformation(fname, fargs));
 				}
 			}
 		}
Index: src/org/eclipse/cdt/ui/FunctionPrototypeSummary.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/FunctionPrototypeSummary.java,v
retrieving revision 1.1
diff -u -r1.1 FunctionPrototypeSummary.java
--- src/org/eclipse/cdt/ui/FunctionPrototypeSummary.java	24 Jun 2003 14:22:14 -0000	1.1
+++ src/org/eclipse/cdt/ui/FunctionPrototypeSummary.java	26 Aug 2003 13:43:07 -0000
@@ -10,26 +10,48 @@
 	String farguments;
 		
 	/**
-	 * Creates a prototype which matches the format
-	 * returntype function(arguments)
-	 * @param properProto
+	 * Create a function prototype summary based on a prototype string.
+	 * @param The string describing the prototype which is properly 
+	 * formed with following format -- returntype function(arguments)
+	 * The following formats will be converted as follows:
+	 * function(arguments) --> void function(arguments)
+	 * returntype function --> returntype function()
+	 * function            --> void function() 
 	 */
 	public FunctionPrototypeSummary(String proto) {
 		int leftbracket = proto.indexOf('(');
 		int rightbracket = proto.lastIndexOf(')');
+		
+		//If there are brackets missing, then assume void parameters
+		if(leftbracket == -1 || rightbracket == -1) {
+			if(leftbracket != -1) {
+				proto = proto.substring(leftbracket) + ")";
+			} else if(rightbracket != -1) {
+				proto = proto.substring(rightbracket - 1) + "()";				
+			} else {
+				proto = proto + "()";
+			}
+		
+			leftbracket = proto.indexOf('(');
+			rightbracket = proto.lastIndexOf(')');
+		} 
+		
 		farguments = proto.substring(leftbracket + 1, rightbracket);
 			
 		int nameend = leftbracket - 1;
 		while(proto.charAt(nameend) == ' ') {
 			nameend--;
 		}
+
 		int namestart = nameend;
 		while(namestart > 0 && proto.charAt(namestart) != ' ') {
 			namestart--;
 		}
+
 		fname = proto.substring(namestart, nameend + 1).trim();
 			
 		if(namestart == 0) {
+			//@@@ Should this be int instead?
 			freturn = "void";
 		} else {
 			freturn = proto.substring(0, namestart).trim();

Back to the top