diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CUIMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CUIMessages.properties index fce98b07d8a..07650d2e997 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CUIMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CUIMessages.properties @@ -16,8 +16,9 @@ ExceptionDialog.seeErrorLogMessage=See error log for more details. ################ # Content Assist ################ -CEditor.contentassist.noCompletions=No completions available. -CEditor.contentassist.timeout=Content Assist parsing has timed out. +CEditor.contentassist.noCompletions=No completions available +CEditor.contentassist.parseError=No completions available due to parse error +CEditor.contentassist.timeout=Content Assist parsing has timed out CAnnotationHover.multipleMarkers=Multiple markers at this line diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor2.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor2.java index 54b9e397885..89ae6ef2492 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor2.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor2.java @@ -17,6 +17,7 @@ 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.IWorkingCopy; +import org.eclipse.cdt.internal.ui.CUIMessages; import org.eclipse.cdt.internal.ui.text.CParameterListValidator; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor; @@ -40,6 +41,10 @@ public class CCompletionProcessor2 implements IContentAssistProcessor { private IEditorPart editor; private String errorMessage; + // Property names + private String assistPrefix = "CEditor.contentassist"; + private String noCompletions = assistPrefix + ".noCompletions"; + private String parseError = assistPrefix + ".parseError"; public CCompletionProcessor2(IEditorPart editor) { this.editor = editor; @@ -51,8 +56,6 @@ public class CCompletionProcessor2 implements IContentAssistProcessor { public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, int offset) { try { - errorMessage = "No completions found"; - long startTime = System.currentTimeMillis(); IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput()); ASTCompletionNode completionNode = CDOM.getInstance().getCompletionNode( @@ -61,6 +64,8 @@ public class CCompletionProcessor2 implements IContentAssistProcessor { CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE)); long stopTime = System.currentTimeMillis(); + errorMessage = CUIMessages.getString(noCompletions); + List proposals = new ArrayList(); IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, "completionContributors"); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionContributor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionContributor.java index f93cedc7875..fe02f270986 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionContributor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionContributor.java @@ -80,6 +80,12 @@ public class DOMCompletionContributor implements ICompletionContributor { if (macros[i].getName().toString().startsWith(prefix)) handleMacro(macros[i], completionNode, offset, viewer, proposals); } + + // Check for the keywords + if (prefix.length() > 0) + for (int i = 0; i < keywords.length; ++i) + if (keywords[i].startsWith(prefix)) + handleKeyword(keywords[i], completionNode, offset, viewer, proposals); } } @@ -191,6 +197,13 @@ public class DOMCompletionContributor implements ICompletionContributor { proposals.add(createProposal(macroName, macroName, image, completionNode, offset, viewer)); } + private void handleKeyword(String keyword, ASTCompletionNode completionNode, int offset, ITextViewer viewer, List proposals) { + // TODO we should really check the context to make sure + // it is valid for the keyword to appear here + Image image = getImage(CElementImageProvider.getKeywordImageDescriptor()); + proposals.add(createProposal(keyword, keyword, image, completionNode, offset, viewer)); + } + private CCompletionProposal createProposal(String repString, String dispString, Image image, ASTCompletionNode completionNode, int offset, ITextViewer viewer) { int repLength = completionNode.getLength(); int repOffset = offset - repLength; @@ -240,5 +253,43 @@ public class DOMCompletionContributor implements ICompletionContributor { ? CUIPlugin.getImageDescriptorRegistry().get( imageDescriptor ) : null; } - + + // These are the keywords we complete + // We only do the ones that are > 5 characters long + private static String [] keywords = { + "const_cast", + "continue", + "default", + "delete", + "double", + "dynamic_cast", + "explicit", + "export", + "extern", + "friend", + "inline", + "mutable", + "namespace", + "operator", + "private", + "protected", + "register", + "reinterpret_cast", + "return", + "signed", + "sizeof", + "static", + "static_cast", + "struct", + "switch", + "template", + "typedef", + "typeid", + "typename", + "unsigned", + "virtual", + "volatile", + "wchar_t" + }; + }