1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Content Assist work

This commit is contained in:
Hoda Amer 2003-12-29 22:01:31 +00:00
parent 27f6d25ecb
commit 93369ee4cd
14 changed files with 159 additions and 43 deletions

View file

@ -1,3 +1,6 @@
2003-12-29 Hoda Amer
Content Assist Work : Moved ICompletionRequestor from core to ui
2003-12-19 Alain Magloire
Added a getCommandLine() method on the CommandLauncher

View file

@ -1,3 +1,9 @@
2003-12-29 Hoda Amer
- Added context checking for completions comming from contributions
- Added preference : Show proposals in Alphabetical Order
- Fix for bug #44043: code assist letter by letter doesn't update properly
- Fix for bug #44251: Code Assist: bad error message on preference page
2003-12-22 Hoda Amer
Content Assist work : Added context information to templates.
Added scope information into relevance calculations

View file

@ -34,7 +34,6 @@ public class CppFunctionContextType extends CompilationUnitContextType {
addVariable(new Type());
addVariable(new Package()); */
addVariable(new Project());
// @@@ Need to add some specific C ones
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.corext.template.ContextType#createContext()

View file

@ -34,7 +34,6 @@ public class CppGlobalContextType extends CompilationUnitContextType {
addVariable(new Type());
addVariable(new Package()); */
addVariable(new Project());
// @@@ Need to add some specific C ones
}
/*

View file

@ -34,7 +34,6 @@ public class CppStructureContextType extends CompilationUnitContextType {
addVariable(new Type());
addVariable(new Package()); */
addVariable(new Project());
// @@@ Need to add some specific C ones
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.corext.template.ContextType#createContext()

View file

@ -12,3 +12,8 @@
Drag.move.problem.title=Drag and Drop Problem
Drag.move.problem.message={0} is read only. Do you still wish to delete it?
ExceptionDialog.seeErrorLogMessage=See error log for more details.
################
# Content Assist
################
CEditor.contentassist.noCompletions=No completions available.

View file

@ -858,11 +858,8 @@ public class CEditorPreferencePage extends PreferencePage implements IWorkbenchP
label = PreferencesMessages.getString("CEditorPreferencePage.ContentAssistPage.insertSingleProposalAutomatically");
addCheckBox(contentAssistComposite, label, ContentAssistPreference.AUTOINSERT, 0);
//label= PreferencesMessages.getString("CEditorPreferencePage.ContentAssistPage.showOnlyProposalsWithCorrectVisibility");
//addCheckBox(contentAssistComposite, label, ContentAssistPreference.SHOW_VISIBLE_PROPOSALS, 0);
//label= PreferencesMessages.getString("CEditorPreferencePage.ContentAssistPage.showProposalsInAlphabeticalOrder");
//addCheckBox(contentAssistComposite, label, ContentAssistPreference.ORDER_PROPOSALS, 0);
label= PreferencesMessages.getString("CEditorPreferencePage.ContentAssistPage.showProposalsInAlphabeticalOrder");
addCheckBox(contentAssistComposite, label, ContentAssistPreference.ORDER_PROPOSALS, 0);
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// The following items are grouped for Auto Activation
@ -1203,14 +1200,14 @@ public class CEditorPreferencePage extends PreferencePage implements IWorkbenchP
private IStatus validatePositiveNumber(String number) {
StatusInfo status = new StatusInfo();
if (number.length() == 0) {
//status.setError("CEditorPreferencePage.empty_input"); //$NON-NLS-1$
status.setError(PreferencesMessages.getString("CEditorPreferencePage.empty_input")); //$NON-NLS-1$
} else {
try {
int value = Integer.parseInt(number);
if (value < 0)
status.setError("CEditorPreferencePage.invalid_input"); //$NON-NLS-1$
status.setError(PreferencesMessages.getString("CEditorPreferencePage.invalid_input")); //$NON-NLS-1$
} catch (NumberFormatException e) {
status.setError("CEditorPreferencePage.invalid_input"); //$NON-NLS-1$
status.setError(PreferencesMessages.getString("CEditorPreferencePage.invalid_input")); //$NON-NLS-1$
}
}
return status;

View file

@ -66,6 +66,9 @@ CEditorPreferencePage.annotationTabTitle= &Annotations
CEditorPreferencePage.colorsTabTitle=&Colors
CEditorPreferencePage.contentAssistTabTitle=Content A&ssist
CEditorPreferencePage.invalid_input=Invalid input.
CEditorPreferencePage.empty_input=Empty input
CEditorPreferencePage.ContentAssistPage.searchGroupTitle=Search scope for completion proposals:
CEditorPreferencePage.ContentAssistPage.searchGroupCurrentFileOption=&Search current file and included files
CEditorPreferencePage.ContentAssistPage.searchGroupCurrentProjectOption=Search current &project

View file

@ -27,6 +27,7 @@ import org.eclipse.cdt.internal.corext.template.ContextTypeRegistry;
import org.eclipse.cdt.internal.corext.template.ITemplateEditor;
import org.eclipse.cdt.internal.ui.CCompletionContributorManager;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.CUIMessages;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.text.CParameterListValidator;
import org.eclipse.cdt.internal.ui.text.template.TemplateEngine;
@ -44,7 +45,9 @@ import org.eclipse.jface.text.contentassist.ContextInformation;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationExtension;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IEditorPart;
/**
@ -52,6 +55,49 @@ import org.eclipse.ui.IEditorPart;
*/
public class CCompletionProcessor implements IContentAssistProcessor {
private static class ContextInformationWrapper implements IContextInformation, IContextInformationExtension {
private final IContextInformation fContextInformation;
private int fPosition;
public ContextInformationWrapper(IContextInformation contextInformation) {
fContextInformation= contextInformation;
}
/*
* @see IContextInformation#getContextDisplayString()
*/
public String getContextDisplayString() {
return fContextInformation.getContextDisplayString();
}
/*
* @see IContextInformation#getImage()
*/
public Image getImage() {
return fContextInformation.getImage();
}
/*
* @see IContextInformation#getInformationDisplayString()
*/
public String getInformationDisplayString() {
return fContextInformation.getInformationDisplayString();
}
/*
* @see IContextInformationExtension#getContextInformationPosition()
*/
public int getContextInformationPosition() {
return fPosition;
}
public void setContextInformationPosition(int position) {
fPosition= position;
}
}
private CEditor fEditor;
private char[] fProposalAutoActivationSet;
private CCompletionProposalComparator fComparator;
@ -64,15 +110,16 @@ public class CCompletionProcessor implements IContentAssistProcessor {
private boolean fRestrictToMatchingCase;
private boolean fAllowAddIncludes;
BasicSearchResultCollector searchResultCollector = null;
ResultCollector resultCollector = null;
CompletionEngine completionEngine = null;
private BasicSearchResultCollector searchResultCollector = null;
private ResultCollector resultCollector = null;
private CompletionEngine completionEngine = null;
SearchEngine searchEngine = null;
CSearchResultLabelProvider labelProvider = null;
private SearchEngine searchEngine = null;
private CSearchResultLabelProvider labelProvider = null;
int currentOffset = 0;
IWorkingCopy currentSourceUnit = null;
private int currentOffset = 0;
private IWorkingCopy currentSourceUnit = null;
private int fNumberOfComputedResults= 0;
public CCompletionProcessor(IEditorPart editor) {
fEditor = (CEditor) editor;
@ -177,7 +224,14 @@ public class CCompletionProcessor implements IContentAssistProcessor {
* @see IContentAssistProcessor#getErrorMessage()
*/
public String getErrorMessage() {
return null;
if (fNumberOfComputedResults == 0) {
String errorMsg= resultCollector.getErrorMessage();
if (errorMsg == null || errorMsg.trim().length() == 0)
errorMsg= CUIMessages.getString("CEditor.contentassist.noCompletions"); //$NON-NLS-1$
return errorMsg;
}
return resultCollector.getErrorMessage();
}
/**
@ -201,7 +255,23 @@ public class CCompletionProcessor implements IContentAssistProcessor {
* @see IContentAssistProcessor#computeContextInformation(ITextViewer, int)
*/
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
return null;
List result= addContextInformations(viewer, offset);
return (IContextInformation[]) result.toArray(new IContextInformation[result.size()]);
}
private List addContextInformations(ITextViewer viewer, int offset) {
ICompletionProposal[] proposals= internalComputeCompletionProposals(viewer, offset);
List result= new ArrayList();
for (int i= 0; i < proposals.length; i++) {
IContextInformation contextInformation= proposals[i].getContextInformation();
if (contextInformation != null) {
ContextInformationWrapper wrapper= new ContextInformationWrapper(contextInformation);
wrapper.setContextInformationPosition(offset);
result.add(wrapper);
}
}
return result;
}
/**
@ -244,8 +314,11 @@ public class CCompletionProcessor implements IContentAssistProcessor {
/**
* @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int)
*/
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
return internalComputeCompletionProposals(viewer, offset);
}
private ICompletionProposal[] internalComputeCompletionProposals(ITextViewer viewer, int offset) {
IWorkingCopyManager fManager = CUIPlugin.getDefault().getWorkingCopyManager();
IWorkingCopy unit = fManager.getWorkingCopy(fEditor.getEditorInput());
@ -265,12 +338,14 @@ public class CCompletionProcessor implements IContentAssistProcessor {
// length = selection.y;
// }
results = evalProposals(document, documentOffset, unit, viewer);
results = evalProposals(document, offset, unit, viewer);
// }
} catch (Exception e) {
CUIPlugin.getDefault().log(e);
}
fNumberOfComputedResults= (results == null ? 0 : results.length);
if (results == null)
results = new ICCompletionProposal[0];
@ -281,7 +356,6 @@ public class CCompletionProcessor implements IContentAssistProcessor {
order(results);
return results;
}
/**
* Order the given proposals.
*/
@ -304,7 +378,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
return null;
// clear the completion list at the result collector
resultCollector.clearCompletions();
resultCollector.reset();
IASTCompletionNode completionNode = addProposalsFromModel(completions);
addProposalsFromSearch(completionNode, completions);
@ -354,6 +428,10 @@ public class CCompletionProcessor implements IContentAssistProcessor {
int offset = currentOffset - prefix.length();
int length = prefix.length();
// calling functions should happen only within the context of a code body
if(completionNode.getCompletionContext() != IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE)
return;
IFunctionSummary[] summary;
summary = CCompletionContributorManager.getDefault().getMatchingFunctions(prefix);
@ -425,7 +503,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
ICSearchScope scope = null;
if (((projectScope) || (projectScopeAndDependency))
&& ( (completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE)
&& ( (completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE)
|| (completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.VARIABLE_TYPE)
|| (completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.FIELD_TYPE) )
&& (prefix.length() > 0)){
@ -435,14 +513,8 @@ public class CCompletionProcessor implements IContentAssistProcessor {
projectScopeElement[0] = (ICElement)currentSourceUnit.getCProject();
scope = SearchEngine.createCSearchScope(projectScopeElement, projectScopeAndDependency);
OrPattern orPattern = new OrPattern();
// search for global variables, functions, classes, structs, unions, enums, macros, and namespaces
orPattern.addPattern(SearchEngine.createSearchPattern(
searchPrefix, ICSearchConstants.VAR, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern(
searchPrefix, ICSearchConstants.FUNCTION, ICSearchConstants.DEFINITIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern(
searchPrefix, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, false ));
OrPattern orPattern = new OrPattern();
orPattern.addPattern(SearchEngine.createSearchPattern(
searchPrefix, ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern(
@ -451,6 +523,15 @@ public class CCompletionProcessor implements IContentAssistProcessor {
searchPrefix, ICSearchConstants.MACRO, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern(
searchPrefix, ICSearchConstants.NAMESPACE, ICSearchConstants.DEFINITIONS, false ));
if( (completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE)){
orPattern.addPattern(SearchEngine.createSearchPattern(
searchPrefix, ICSearchConstants.VAR, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern(
searchPrefix, ICSearchConstants.FUNCTION, ICSearchConstants.DEFINITIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern(
searchPrefix, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, false ));
}
searchEngine.search(CUIPlugin.getWorkspace(), orPattern, scope, searchResultCollector, true);
elementsFound.addAll(searchResultCollector.getSearchResults());

View file

@ -286,7 +286,7 @@ public class CCompletionProposal implements ICCompletionProposal, ICompletionPro
return false;
int replacementLength= fReplacementString == null ? 0 : fReplacementString.length();
if (offset >= fReplacementOffset + replacementLength)
if (offset > fReplacementOffset + replacementLength)
return false;
try {

View file

@ -17,7 +17,6 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICompletionRequestor;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.parser.IParser;

View file

@ -10,7 +10,7 @@
***********************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist;
import org.eclipse.cdt.core.ICompletionRequestor;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
/**
@ -137,4 +137,12 @@ public class CompletionRequestorAdaptor implements ICompletionRequestor {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.ICompletionRequestor#acceptError(org.eclipse.cdt.core.parser.IProblem)
*/
public void acceptError(IProblem error) {
// TODO Auto-generated method stub
}
}

View file

@ -8,8 +8,9 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.core;
package org.eclipse.cdt.internal.ui.text.contentassist;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
/**
@ -32,4 +33,5 @@ public interface ICompletionRequestor {
void acceptEnumeration(String name, int completionStart, int completionLength, int relevance);
void acceptEnumerator(String name, int completionStart, int completionLength, int relevance);
void acceptKeyword(String name, int completionStart, int completionLength, int relevance);
void acceptError(IProblem error);
}

View file

@ -11,9 +11,9 @@
package org.eclipse.cdt.internal.ui.text.contentassist;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.internal.ui.CElementImageProvider;
import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
@ -35,6 +35,7 @@ import org.eclipse.swt.graphics.Image;
public class ResultCollector extends CompletionRequestorAdaptor {
private Set completions = new HashSet();
private ImageDescriptorRegistry registry = CUIPlugin.getImageDescriptorRegistry();
private IProblem fLastProblem;
public ResultCollector(){
completions.clear();
@ -46,8 +47,9 @@ public class ResultCollector extends CompletionRequestorAdaptor {
public Set getCompletions() {
return completions;
}
public void clearCompletions() {
public void reset() {
completions.clear();
fLastProblem = null;
}
/*
* Create a proposal
@ -459,4 +461,17 @@ public class ResultCollector extends CompletionRequestorAdaptor {
completions.add(proposal);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.ICompletionRequestor#acceptError(org.eclipse.cdt.core.parser.IProblem)
*/
public void acceptError(IProblem error) {
fLastProblem = error;
}
public String getErrorMessage() {
if (fLastProblem != null)
return fLastProblem.getMessage();
return ""; //$NON-NLS-1$
}
}