mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-11 10:15: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:
parent
66fdaff822
commit
93e17563e0
3 changed files with 62 additions and 5 deletions
|
@ -16,8 +16,9 @@ ExceptionDialog.seeErrorLogMessage=See error log for more details.
|
||||||
################
|
################
|
||||||
# Content Assist
|
# Content Assist
|
||||||
################
|
################
|
||||||
CEditor.contentassist.noCompletions=No completions available.
|
CEditor.contentassist.noCompletions=No completions available
|
||||||
CEditor.contentassist.timeout=Content Assist parsing has timed out.
|
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
|
CAnnotationHover.multipleMarkers=Multiple markers at this line
|
||||||
|
|
||||||
|
|
|
@ -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.IASTServiceProvider.UnsupportedDialectException;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
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.internal.ui.text.CParameterListValidator;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor;
|
import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor;
|
||||||
|
@ -40,6 +41,10 @@ public class CCompletionProcessor2 implements IContentAssistProcessor {
|
||||||
private IEditorPart editor;
|
private IEditorPart editor;
|
||||||
private String errorMessage;
|
private String errorMessage;
|
||||||
|
|
||||||
|
// Property names
|
||||||
|
private String assistPrefix = "CEditor.contentassist";
|
||||||
|
private String noCompletions = assistPrefix + ".noCompletions";
|
||||||
|
private String parseError = assistPrefix + ".parseError";
|
||||||
|
|
||||||
public CCompletionProcessor2(IEditorPart editor) {
|
public CCompletionProcessor2(IEditorPart editor) {
|
||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
|
@ -51,8 +56,6 @@ public class CCompletionProcessor2 implements IContentAssistProcessor {
|
||||||
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer,
|
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer,
|
||||||
int offset) {
|
int offset) {
|
||||||
try {
|
try {
|
||||||
errorMessage = "No completions found";
|
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
|
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
|
||||||
ASTCompletionNode completionNode = CDOM.getInstance().getCompletionNode(
|
ASTCompletionNode completionNode = CDOM.getInstance().getCompletionNode(
|
||||||
|
@ -61,6 +64,8 @@ public class CCompletionProcessor2 implements IContentAssistProcessor {
|
||||||
CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE));
|
CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE));
|
||||||
long stopTime = System.currentTimeMillis();
|
long stopTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
errorMessage = CUIMessages.getString(noCompletions);
|
||||||
|
|
||||||
List proposals = new ArrayList();
|
List proposals = new ArrayList();
|
||||||
|
|
||||||
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, "completionContributors"); //$NON-NLS-1$
|
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, "completionContributors"); //$NON-NLS-1$
|
||||||
|
|
|
@ -80,6 +80,12 @@ public class DOMCompletionContributor implements ICompletionContributor {
|
||||||
if (macros[i].getName().toString().startsWith(prefix))
|
if (macros[i].getName().toString().startsWith(prefix))
|
||||||
handleMacro(macros[i], completionNode, offset, viewer, proposals);
|
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));
|
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) {
|
private CCompletionProposal createProposal(String repString, String dispString, Image image, ASTCompletionNode completionNode, int offset, ITextViewer viewer) {
|
||||||
int repLength = completionNode.getLength();
|
int repLength = completionNode.getLength();
|
||||||
int repOffset = offset - repLength;
|
int repOffset = offset - repLength;
|
||||||
|
@ -240,5 +253,43 @@ public class DOMCompletionContributor implements ICompletionContributor {
|
||||||
? CUIPlugin.getImageDescriptorRegistry().get( imageDescriptor )
|
? CUIPlugin.getImageDescriptorRegistry().get( imageDescriptor )
|
||||||
: null;
|
: 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"
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue