[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-dev] Giving more context to ICHelpProvider implementations
|
ICHelpProvider implementations provide three types of user support: Help file
URLs from an identifier, tooltip content from an identifier and code
completion suggestions from an identifier prefix. In each case the method
which is called gets a context object (ICHelpInvocationContext) which
provides references to the project (IProject) and the translation unit
(ITranslationUnit).
There is, however, no information about the role that the identifier(-prefix)
is playing in it's context. Is it a function call, a method call, a structure
member or an enumeration identifier ... ? For this reason I would like to
discuss an enhancement by which the context will be augmented and also return
the ASTCompletionNode for the identifier(-prefix). From the completion node
the role of the identifier could be determined. The following changes will be
required:
- Augment ICHelpInvocationContext with a getter for the ASTCompletionNode.
- Try to determine the completion node in all places where an
ICHelpInvocationContext object gets created. This is the case in
-- CDocHover.getHoverInfo() for tooltip information.
-- CHelpDisplayContext.CHelpDisplayContext() for help page URLs.
-- HelpCompletionContributor.contributeCompletionProposals() for completion
proposals.
-- CCompletionProcessor.addProposalsFromCompletionContributors() to satisfy
the compiler (CCompletionProcessor is not in use anymore)
I did the implementations and have attached the patch to help you get an idea
of what I am trying to do. I found the implementation feasible and fairly
straightforward, test results however leave some open questions:
-- HelpCompletionContributor.contributeCompletionProposals(): Implementation
works and does compute a functioning ASTCompletionNode.
-- CDocHover.getHoverInfo(): The translation unit returns a null
ASTCompletionNode.
-- CHelpDisplayContext.CHelpDisplayContext(): The translation unit returns a
null ASTCompletionNode.
So one works, two don't. Am I making false assumptions here? Can a completion
node only be computed for incomplete identifiers? If somebody knows, please
help me out.
Apart from that I would invite you to take a look at the patch and my ideas
and comment upon them. I have created
https://bugs.eclipse.org/bugs/show_bug.cgi?id=122601 to track the discussion.
Thanks,
Norbert
Index: src-cdtui/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java
===================================================================
RCS file: /home/pn3484/CVSData/org.eclipse.cdt.ui/src-cdtui/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java,v
retrieving revision 1.1
diff -u -r1.1 AddIncludeOnSelectionAction.java
--- src-cdtui/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java 4 Nov 2005 20:58:22 -0000 1.1
+++ src-cdtui/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java 4 Jan 2006 08:23:56 -0000
@@ -24,9 +24,11 @@
import org.eclipse.cdt.core.browser.PathUtil;
import org.eclipse.cdt.core.browser.QualifiedTypeName;
import org.eclipse.cdt.core.browser.TypeSearchScope;
+import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchScope;
@@ -225,6 +227,10 @@
public ITranslationUnit getTranslationUnit() {
return AddIncludeOnSelectionAction.this.getTranslationUnit();
}
+
+ public ASTCompletionNode getCompletionNode() {
+ return null ;
+ }
};
fs[0] = CHelpProviderManager.getDefault().getFunctionInfo(context, name);
Index: src-cdtui/org/eclipse/cdt/internal/ui/text/c/hover/CDocHover.java
===================================================================
RCS file: /home/pn3484/CVSData/org.eclipse.cdt.ui/src-cdtui/org/eclipse/cdt/internal/ui/text/c/hover/CDocHover.java,v
retrieving revision 1.1
diff -u -r1.1 CDocHover.java
--- src-cdtui/org/eclipse/cdt/internal/ui/text/c/hover/CDocHover.java 4 Nov 2005 20:58:22 -0000 1.1
+++ src-cdtui/org/eclipse/cdt/internal/ui/text/c/hover/CDocHover.java 4 Jan 2006 08:23:56 -0000
@@ -11,20 +11,28 @@
package org.eclipse.cdt.internal.ui.text.c.hover;
+import org.eclipse.cdt.core.dom.CDOM;
+import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.model.IWorkingCopy;
+import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.internal.ui.CHelpProviderManager;
import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
import org.eclipse.cdt.internal.ui.text.CWordFinder;
import org.eclipse.cdt.internal.ui.text.HTMLPrinter;
+import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IFunctionSummary;
import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IStorage;
import org.eclipse.jface.text.IRegion;
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;
public class CDocHover extends AbstractCEditorTextHover {
@@ -51,7 +59,37 @@
StringBuffer buffer = new StringBuffer();
// call the Help to get info
+
+ ASTCompletionNode completionNode = null ;
+ int offset = region.getOffset();
+
+ IEditorPart part = getEditor();
+ if (null!=part) {
+ IEditorInput input = part.getEditorInput() ;
+ if (null!=input) {
+ IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(input);
+ IFile file = (IFile)workingCopy.getResource();
+ if (file != null)
+ completionNode = CDOM.getInstance().getCompletionNode(
+ file,
+ offset,
+ CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE));
+ else if (input instanceof ExternalEditorInput) {
+ IStorage storage = ((ExternalEditorInput)(input)).getStorage();
+ IProject project = workingCopy.getCProject().getProject();
+ completionNode = CDOM.getInstance().getCompletionNode(
+ storage,
+ project,
+ offset,
+ CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE));
+ }
+ else {
+ completionNode = null ;
+ }
+ }
+ }
+ final ASTCompletionNode finalCompletionNode = completionNode ;
ICHelpInvocationContext context = new ICHelpInvocationContext() {
public IProject getProject() {
@@ -66,6 +104,11 @@
IEditorInput editorInput= getEditor().getEditorInput();
return CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
}
+
+ public ASTCompletionNode getCompletionNode() {
+ return finalCompletionNode ;
+ }
+
};
IFunctionSummary fs = CHelpProviderManager.getDefault().getFunctionInfo(context, expression);
Index: src-cdtui/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor.java
===================================================================
RCS file: /home/pn3484/CVSData/org.eclipse.cdt.ui/src-cdtui/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor.java,v
retrieving revision 1.1
diff -u -r1.1 CCompletionProcessor.java
--- src-cdtui/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor.java 4 Nov 2005 20:58:22 -0000 1.1
+++ src-cdtui/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor.java 4 Jan 2006 08:23:56 -0000
@@ -17,6 +17,7 @@
import java.util.List;
import java.util.Vector;
+import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
@@ -400,7 +401,7 @@
IFunctionSummary[] summary;
ICHelpInvocationContext context = new ICHelpInvocationContext() {
-
+
public IProject getProject() {
return fCurrentSourceUnit.getCProject().getProject();
}
@@ -408,6 +409,11 @@
public ITranslationUnit getTranslationUnit() {
return fCurrentSourceUnit;
}
+
+ public ASTCompletionNode getCompletionNode() {
+ return null ;
+ }
+
};
summary = CHelpProviderManager.getDefault().getMatchingFunctions(context, prefix);
if(summary == null) {
Index: src-cdtui/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionContributor.java
===================================================================
RCS file: /home/pn3484/CVSData/org.eclipse.cdt.ui/src-cdtui/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionContributor.java,v
retrieving revision 1.1
diff -u -r1.1 HelpCompletionContributor.java
--- src-cdtui/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionContributor.java 4 Nov 2005 20:58:22 -0000 1.1
+++ src-cdtui/org/eclipse/cdt/internal/ui/text/contentassist/HelpCompletionContributor.java 4 Jan 2006 08:23:56 -0000
@@ -17,6 +17,7 @@
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
+import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.internal.ui.CHelpProviderManager;
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
import org.eclipse.cdt.ui.CUIPlugin;
@@ -35,6 +36,7 @@
List proposals)
{
final IWorkingCopy fWorkingCopy = workingCopy;
+ final ASTCompletionNode finalCompletionNode = completionNode ;
if (completionNode != null) {
// Find matching functions
ICHelpInvocationContext context = new ICHelpInvocationContext() {
@@ -46,6 +48,9 @@
public ITranslationUnit getTranslationUnit() {
return fWorkingCopy.getTranslationUnit();
}
+ public ASTCompletionNode getCompletionNode() {
+ return finalCompletionNode ;
+ }
};
IASTName[] names = completionNode.getNames();
Index: src-cdtui/org/eclipse/cdt/internal/ui/util/CHelpDisplayContext.java
===================================================================
RCS file: /home/pn3484/CVSData/org.eclipse.cdt.ui/src-cdtui/org/eclipse/cdt/internal/ui/util/CHelpDisplayContext.java,v
retrieving revision 1.1
diff -u -r1.1 CHelpDisplayContext.java
--- src-cdtui/org/eclipse/cdt/internal/ui/util/CHelpDisplayContext.java 4 Nov 2005 20:58:28 -0000 1.1
+++ src-cdtui/org/eclipse/cdt/internal/ui/util/CHelpDisplayContext.java 4 Jan 2006 08:23:56 -0000
@@ -16,14 +16,21 @@
import java.util.Arrays;
import java.util.List;
+import org.eclipse.cdt.core.dom.CDOM;
+import org.eclipse.cdt.core.dom.IASTServiceProvider.UnsupportedDialectException;
+import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.model.IWorkingCopy;
+import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.internal.ui.CHelpProviderManager;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.text.CWordFinder;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.ICHelpResourceDescriptor;
import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.help.HelpSystem;
import org.eclipse.help.IContext;
@@ -70,6 +77,30 @@
List helpResources= new ArrayList();
+ IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
+ IFile file = (IFile)workingCopy.getResource();
+ int offset = 0 ; // FIXME: must get offset from editor!
+ ASTCompletionNode completionNode = null ;
+ try {
+ if (file != null)
+ completionNode = CDOM.getInstance().getCompletionNode(
+ file,
+ offset,
+ CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE));
+ else if (editor.getEditorInput() instanceof ExternalEditorInput) {
+ IStorage storage = ((ExternalEditorInput)(editor.getEditorInput())).getStorage();
+ IProject project = workingCopy.getCProject().getProject();
+ completionNode = CDOM.getInstance().getCompletionNode(
+ storage,
+ project,
+ offset,
+ CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE));
+ }
+ } catch (UnsupportedDialectException e) {
+ // No need for any action!
+ }
+
+ final ASTCompletionNode finalCompletionNode = completionNode ;
ICHelpInvocationContext invocationContext = new ICHelpInvocationContext() {
public IProject getProject() {
@@ -84,6 +115,10 @@
IEditorInput editorInput= editor.getEditorInput();
return CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
}
+
+ public ASTCompletionNode getCompletionNode() {
+ return finalCompletionNode ;
+ }
};
if (context != null) {
Index: src-cdtui/org/eclipse/cdt/ui/dialogs/CHelpConfigurationPropertyPage.java
===================================================================
RCS file: /home/pn3484/CVSData/org.eclipse.cdt.ui/src-cdtui/org/eclipse/cdt/ui/dialogs/CHelpConfigurationPropertyPage.java,v
retrieving revision 1.1
diff -u -r1.1 CHelpConfigurationPropertyPage.java
--- src-cdtui/org/eclipse/cdt/ui/dialogs/CHelpConfigurationPropertyPage.java 4 Nov 2005 20:58:22 -0000 1.1
+++ src-cdtui/org/eclipse/cdt/ui/dialogs/CHelpConfigurationPropertyPage.java 4 Jan 2006 08:23:56 -0000
@@ -14,7 +14,9 @@
import java.util.Arrays;
import java.util.List;
+import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.internal.ui.CHelpProviderManager;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.CUIMessages;
@@ -111,6 +113,7 @@
fCHelpBookDescriptors = CHelpProviderManager.getDefault().getCHelpBookDescriptors(new ICHelpInvocationContext(){
public IProject getProject(){return (IProject)resource;}
public ITranslationUnit getTranslationUnit(){return null;}
+ public ASTCompletionNode getCompletionNode() {return null ;}
}
);
@@ -146,6 +149,7 @@
CHelpProviderManager.getDefault().serialize(new ICHelpInvocationContext(){
public IProject getProject(){return project;}
public ITranslationUnit getTranslationUnit(){return null;}
+ public ASTCompletionNode getCompletionNode() {return null ;}
});
}
}
Index: src-cdtui/org/eclipse/cdt/ui/text/ICHelpInvocationContext.java
===================================================================
RCS file: /home/pn3484/CVSData/org.eclipse.cdt.ui/src-cdtui/org/eclipse/cdt/ui/text/ICHelpInvocationContext.java,v
retrieving revision 1.1
diff -u -r1.1 ICHelpInvocationContext.java
--- src-cdtui/org/eclipse/cdt/ui/text/ICHelpInvocationContext.java 4 Nov 2005 20:58:32 -0000 1.1
+++ src-cdtui/org/eclipse/cdt/ui/text/ICHelpInvocationContext.java 4 Jan 2006 08:23:56 -0000
@@ -11,7 +11,9 @@
package org.eclipse.cdt.ui.text;
+import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.core.resources.IProject;
/**
@@ -28,5 +30,11 @@
* @return ITranslationUnit or null
*/
ITranslationUnit getTranslationUnit();
+
+ /**
+ *
+ * @return Completionnode for this invocation or null
+ */
+ ASTCompletionNode getCompletionNode();
}