1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-11 02:05:39 +02:00

Added handling for keywords. Externalize the error message actually made use of the one that was already there).

This commit is contained in:
Doug Schaefer 2005-04-05 19:27:38 +00:00
parent 66fdaff822
commit 93e17563e0
3 changed files with 62 additions and 5 deletions

View file

@ -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

View file

@ -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$

View file

@ -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;
@ -241,4 +254,42 @@ public class DOMCompletionContributor implements ICompletionContributor {
: 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"
};
}