Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: Applied: [cdt-patch] Hover help re-enablement

Thanks

Thomas Fletcher wrote:

Folks,

 Some time during the summer I submitted a patch to add the display
of arguments to the C/C++ editor when code completion was invoked.
Somehow I managed to submit a patch which commented out all of the
hover extension point code at the same time.  This patch, targetted
at the 1.2 branch but also applicable to head re-enables the hover
using only the basic extension point.  While we are likely going to
change the scheme for 2.0, there are products today which use this
extension point so it should be at least maintained until the replacement is available.

ChangeLog:

 Re-activate the hover help based on the function summary extension
point. Fix a bug in the FunctionSummary class which displayed arguments as
 the return value for functions.

------------------------------------------------------------------------

Index: src/org/eclipse/cdt/internal/ui/editor/DefaultCEditorTextHover.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/DefaultCEditorTextHover.java,v
retrieving revision 1.6
diff -u -r1.6 DefaultCEditorTextHover.java
--- src/org/eclipse/cdt/internal/ui/editor/DefaultCEditorTextHover.java	23 Sep 2003 15:17:20 -0000	1.6
+++ src/org/eclipse/cdt/internal/ui/editor/DefaultCEditorTextHover.java	12 Dec 2003 05:39:42 -0000
@@ -5,24 +5,16 @@
 * All Rights Reserved.
 */

-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.cdt.internal.ui.CCompletionContributorManager;
+import org.eclipse.cdt.internal.ui.text.CWordFinder;
+import org.eclipse.cdt.internal.ui.text.HTMLPrinter;
+import org.eclipse.cdt.ui.IFunctionSummary;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
import org.eclipse.swt.graphics.Point;
-import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
-
-
-import org.eclipse.cdt.internal.ui.CCompletionContributorManager;
-import org.eclipse.cdt.internal.ui.text.CWordFinder;
-import org.eclipse.cdt.internal.ui.text.HTMLPrinter;
-import org.eclipse.cdt.ui.IFunctionSummary;

public class DefaultCEditorTextHover implements ITextHover {
@@ -41,31 +33,32 @@
	 */
public String getHoverInfo( ITextViewer viewer, IRegion region ) {
-//		String expression = null;
-//		
-// if(fEditor == null) -// return null;
-//		try
-//		{
-//			expression = viewer.getDocument().get( region.getOffset(), region.getLength() );
-//			expression = expression.trim();
-//			if ( expression.length() == 0 )
-// return null; -//
-//			StringBuffer buffer = new StringBuffer();
-//
-//			// We are just doing some C, call the Help to get info
-//
-//			IFunctionSummary fs = CCompletionContributorManager.getDefault().getFunctionInfo(expression);
-//			if(fs != null) {
-//				buffer.append("<b>");
-//				buffer.append(HTMLPrinter.convertToHTMLContent(fs.getName()));
-//				buffer.append("()</b>");
-//				buffer.append(HTMLPrinter.convertToHTMLContent(fs.getPrototype().getPrototypeString(false)));
-//				if(fs.getDescription() != null) {
-//					buffer.append("<br><br>");
-//					buffer.append(HTMLPrinter.convertToHTMLContent(fs.getDescription()));
-//				}
+		String expression = null;
+		
+ if(fEditor == null) + return null;
+		try
+		{
+			expression = viewer.getDocument().get( region.getOffset(), region.getLength() );
+			expression = expression.trim();
+			if ( expression.length() == 0 )
+ return null; +
+			StringBuffer buffer = new StringBuffer();
+
+			// We are just doing some C, call the Help to get info
+
+			IFunctionSummary fs = CCompletionContributorManager.getDefault().getFunctionInfo(expression);
+			if(fs != null) {
+				buffer.append("<b>Name:</b> ");
+				buffer.append(HTMLPrinter.convertToHTMLContent(fs.getName()));
+				buffer.append("<br><b>Protoype:</b> ");
+				buffer.append(HTMLPrinter.convertToHTMLContent(fs.getPrototype().getPrototypeString(false)));
+				if(fs.getDescription() != null) {
+					buffer.append("<br><b>Description:</b><br>");
+					//Don't convert this description since it could already be formatted
+					buffer.append(fs.getDescription());
+				}
//				int i;
//				for(i = 0; i < buffer.length(); i++) {
//					if(buffer.charAt(i) == '\\') {
@@ -74,7 +67,8 @@
//						}
//					}
//				}
-//			} else {
+ } +// else {
//				// Query the C model
//				IndexModel model = IndexModel.getDefault();
//				IEditorInput input = fEditor.getEditorInput();
@@ -109,20 +103,15 @@
//					}	
//				}
//			}
-//			if (buffer.length() > 0) {
-//				HTMLPrinter.insertPageProlog(buffer, 0);
-//				HTMLPrinter.addPageEpilog(buffer);
-//				return buffer.toString();
-//			}
-//		}
-//		catch( BadLocationException x )
-//		{
-//			// ignore
-//		}
-//		catch( CoreException x )
-//		{
-//			// ignore
-//		}
+			if (buffer.length() > 0) {
+				HTMLPrinter.insertPageProlog(buffer, 0);
+				HTMLPrinter.addPageEpilog(buffer);
+				return buffer.toString();
+			}
+		} catch(Exception ex) {
+			/* Ignore */
+		}
+		
		return null;
	}

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.2
diff -u -r1.2 FunctionPrototypeSummary.java
--- src/org/eclipse/cdt/ui/FunctionPrototypeSummary.java	27 Aug 2003 13:17:47 -0000	1.2
+++ src/org/eclipse/cdt/ui/FunctionPrototypeSummary.java	12 Dec 2003 05:39:43 -0000
@@ -73,7 +73,7 @@
	public String getPrototypeString(boolean namefirst) {
		StringBuffer buffer = new StringBuffer();
		if(!namefirst) {
-			buffer.append(getArguments());
+			buffer.append(getReturnType());
			buffer.append(" ");
		}
		buffer.append(getName());



Back to the top