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

Bug 488904 - Added a preference for enabling/disabling argument guessing

Change-Id: Id39454da16638d5f11c95e419c2385dc16cdb53a
This commit is contained in:
Sergey Prigogin 2016-03-02 20:35:39 -08:00
parent 86dabd3d00
commit 70fe6cbbde
6 changed files with 70 additions and 57 deletions

View file

@ -12,6 +12,7 @@
* Kirk Beitz (Nokia) * Kirk Beitz (Nokia)
* Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion) * Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
* Thomas Corbat * Thomas Corbat
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.preferences; package org.eclipse.cdt.internal.ui.preferences;
@ -48,6 +49,7 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage {
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, ContentAssistPreference.AUTOACTIVATION_DELAY)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, ContentAssistPreference.AUTOACTIVATION_DELAY));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.AUTOINSERT)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.AUTOINSERT));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.PREFIX_COMPLETION)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.PREFIX_COMPLETION));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.GUESS_ARGUMENTS));
// overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, ContentAssistPreference.TIMEOUT_DELAY)); // overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, ContentAssistPreference.TIMEOUT_DELAY));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOT)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOT));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_ARROW)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_ARROW));
@ -106,6 +108,9 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage {
label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_insertCommonProposalAutomatically; label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_insertCommonProposalAutomatically;
addCheckBox(insertionGroup, label, ContentAssistPreference.PREFIX_COMPLETION, 0); addCheckBox(insertionGroup, label, ContentAssistPreference.PREFIX_COMPLETION, 0);
label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_guessArguments;
addCheckBox(insertionGroup, label, ContentAssistPreference.GUESS_ARGUMENTS, 0);
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// sorting and filtering // sorting and filtering
label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_sortingSection_title; label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_sortingSection_title;
@ -138,7 +143,7 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage {
addCheckBox(enableGroup, label, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW, 0); addCheckBox(enableGroup, label, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW, 0);
label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_autoActivationDelay; label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_autoActivationDelay;
addTextField(enableGroup, label, ContentAssistPreference.AUTOACTIVATION_DELAY, 4, 0, true); addTextField(enableGroup, label, ContentAssistPreference.AUTOACTIVATION_DELAY, 4, 4, true);
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// The following items are grouped for Default Arguments // The following items are grouped for Default Arguments
@ -181,6 +186,7 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage {
store.setDefault(ContentAssistPreference.AUTOINSERT, true); store.setDefault(ContentAssistPreference.AUTOINSERT, true);
store.setDefault(ContentAssistPreference.PREFIX_COMPLETION, true); store.setDefault(ContentAssistPreference.PREFIX_COMPLETION, true);
store.setDefault(ContentAssistPreference.GUESS_ARGUMENTS, true);
store.setDefault(ContentAssistPreference.ORDER_PROPOSALS, false); store.setDefault(ContentAssistPreference.ORDER_PROPOSALS, false);
store.setDefault(ContentAssistPreference.PROPOSALS_FILTER, store.setDefault(ContentAssistPreference.PROPOSALS_FILTER,
ProposalFilterPreferencesUtil.getProposalFilternamesAsString()); ProposalFilterPreferencesUtil.getProposalFilternamesAsString());

View file

@ -42,6 +42,7 @@ public final class PreferencesMessages extends NLS {
public static String CEditorPreferencePage_ContentAssistPage_insertionGroupTitle; public static String CEditorPreferencePage_ContentAssistPage_insertionGroupTitle;
public static String CEditorPreferencePage_ContentAssistPage_insertSingleProposalAutomatically; public static String CEditorPreferencePage_ContentAssistPage_insertSingleProposalAutomatically;
public static String CEditorPreferencePage_ContentAssistPage_insertCommonProposalAutomatically; public static String CEditorPreferencePage_ContentAssistPage_insertCommonProposalAutomatically;
public static String CEditorPreferencePage_ContentAssistPage_guessArguments;
public static String CEditorPreferencePage_ContentAssistPage_showProposalsInAlphabeticalOrder; public static String CEditorPreferencePage_ContentAssistPage_showProposalsInAlphabeticalOrder;
public static String CEditorPreferencePage_ContentAssistPage_showCamelCaseMatches; public static String CEditorPreferencePage_ContentAssistPage_showCamelCaseMatches;
public static String CEditorPreferencePage_ContentAssistPage_autoActivationGroupTitle; public static String CEditorPreferencePage_ContentAssistPage_autoActivationGroupTitle;

View file

@ -26,8 +26,9 @@ CEditorPreferencePage_colors=Synta&x
#CEditorPreferencePage_ContentAssistPage_searchGroupCurrentFileOption=S&earch current file and included files #CEditorPreferencePage_ContentAssistPage_searchGroupCurrentFileOption=S&earch current file and included files
#CEditorPreferencePage_ContentAssistPage_searchGroupCurrentProjectOption=Search current &project #CEditorPreferencePage_ContentAssistPage_searchGroupCurrentProjectOption=Search current &project
CEditorPreferencePage_ContentAssistPage_insertionGroupTitle=Insertion CEditorPreferencePage_ContentAssistPage_insertionGroupTitle=Insertion
CEditorPreferencePage_ContentAssistPage_insertSingleProposalAutomatically=&Insert single proposals automatically CEditorPreferencePage_ContentAssistPage_insertSingleProposalAutomatically=&Insert a single proposal automatically
CEditorPreferencePage_ContentAssistPage_insertCommonProposalAutomatically=I&nsert common prefixes automatically CEditorPreferencePage_ContentAssistPage_insertCommonProposalAutomatically=I&nsert common prefixes automatically
CEditorPreferencePage_ContentAssistPage_guessArguments=&Fill function arguments and show guessed arguments
CEditorPreferencePage_ContentAssistPage_showProposalsInAlphabeticalOrder=Present proposals in a&lphabetical order CEditorPreferencePage_ContentAssistPage_showProposalsInAlphabeticalOrder=Present proposals in a&lphabetical order
CEditorPreferencePage_ContentAssistPage_showCamelCaseMatches=Show ca&mel case matches CEditorPreferencePage_ContentAssistPage_showCamelCaseMatches=Show ca&mel case matches
CEditorPreferencePage_ContentAssistPage_autoActivationGroupTitle=Auto-Activation CEditorPreferencePage_ContentAssistPage_autoActivationGroupTitle=Auto-Activation

View file

@ -4,12 +4,13 @@
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
* Kirk Beitz (Nokia) * Kirk Beitz (Nokia)
* Thomas Corbat (IFS) * Thomas Corbat (IFS)
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist; package org.eclipse.cdt.internal.ui.text.contentassist;
@ -78,7 +79,7 @@ public class ContentAssistPreference {
public final static String PROJECT_SEARCH_SCOPE= "content_assist_project_search_scope"; //$NON-NLS-1$ public final static String PROJECT_SEARCH_SCOPE= "content_assist_project_search_scope"; //$NON-NLS-1$
/** Preference key for completion filtering */ /** Preference key for completion filtering */
public final static String PROPOSALS_FILTER= "content_assist_proposal_filter"; //$NON-NLS-1$ public final static String PROPOSALS_FILTER= "content_assist_proposal_filter"; //$NON-NLS-1$
/** Key for boolean preference telling whether camel case/underscore matches are to be shown by content assist features or not*/ /** Key for boolean preference telling whether camel case/underscore matches are to be shown by content assist features or not*/
public static final String SHOW_CAMEL_CASE_MATCHES = "contentAssist.showCamelCaseMatches"; //$NON-NLS-1$ public static final String SHOW_CAMEL_CASE_MATCHES = "contentAssist.showCamelCaseMatches"; //$NON-NLS-1$
@ -86,19 +87,19 @@ public class ContentAssistPreference {
RGB rgb= PreferenceConverter.getColor(store, key); RGB rgb= PreferenceConverter.getColor(store, key);
return manager.getColor(rgb); return manager.getColor(rgb);
} }
private static Color getColor(IPreferenceStore store, String key) { private static Color getColor(IPreferenceStore store, String key) {
CTextTools textTools= CUIPlugin.getDefault().getTextTools(); CTextTools textTools= CUIPlugin.getDefault().getTextTools();
return getColor(store, key, textTools.getColorManager()); return getColor(store, key, textTools.getColorManager());
} }
private static CContentAssistProcessor getCProcessor(ContentAssistant assistant) { private static CContentAssistProcessor getCProcessor(ContentAssistant assistant) {
IContentAssistProcessor p= assistant.getContentAssistProcessor(IDocument.DEFAULT_CONTENT_TYPE); IContentAssistProcessor p= assistant.getContentAssistProcessor(IDocument.DEFAULT_CONTENT_TYPE);
if (p instanceof CContentAssistProcessor) if (p instanceof CContentAssistProcessor)
return (CContentAssistProcessor) p; return (CContentAssistProcessor) p;
return null; return null;
} }
private static void configureCProcessor(ContentAssistant assistant, IPreferenceStore store) { private static void configureCProcessor(ContentAssistant assistant, IPreferenceStore store) {
CContentAssistProcessor ccp= getCProcessor(assistant); CContentAssistProcessor ccp= getCProcessor(assistant);
if (ccp == null) if (ccp == null)
@ -111,10 +112,10 @@ public class ContentAssistPreference {
// //
// enabled= store.getBoolean(CASE_SENSITIVITY); // enabled= store.getBoolean(CASE_SENSITIVITY);
// ccp.restrictProposalsToMatchingCases(enabled); // ccp.restrictProposalsToMatchingCases(enabled);
// enabled= store.getBoolean(ORDER_PROPOSALS); // enabled= store.getBoolean(ORDER_PROPOSALS);
// ccp.orderProposalsAlphabetically(enabled); // ccp.orderProposalsAlphabetically(enabled);
// enabled= store.getBoolean(ADD_INCLUDE); // enabled= store.getBoolean(ADD_INCLUDE);
// ccp.allowAddingIncludes(enabled); // ccp.allowAddingIncludes(enabled);
} }
@ -148,14 +149,14 @@ public class ContentAssistPreference {
triggers = "."; //$NON-NLS-1$ triggers = "."; //$NON-NLS-1$
ccp.setReplacementAutoActivationCharacters(triggers); ccp.setReplacementAutoActivationCharacters(triggers);
} }
/** /**
* Configure the given content assistant from the given store. * Configure the given content assistant from the given store.
*/ */
public static void configure(ContentAssistant assistant, IPreferenceStore store) { public static void configure(ContentAssistant assistant, IPreferenceStore store) {
CTextTools textTools= CUIPlugin.getDefault().getTextTools(); CTextTools textTools= CUIPlugin.getDefault().getTextTools();
IColorManager manager= textTools.getColorManager(); IColorManager manager= textTools.getColorManager();
boolean enabledDot= store.getBoolean(AUTOACTIVATION_TRIGGERS_DOT); boolean enabledDot= store.getBoolean(AUTOACTIVATION_TRIGGERS_DOT);
boolean enabledArrow= store.getBoolean(AUTOACTIVATION_TRIGGERS_ARROW); boolean enabledArrow= store.getBoolean(AUTOACTIVATION_TRIGGERS_ARROW);
boolean enabledDoubleColon= store.getBoolean(AUTOACTIVATION_TRIGGERS_DOUBLECOLON); boolean enabledDoubleColon= store.getBoolean(AUTOACTIVATION_TRIGGERS_DOUBLECOLON);
@ -163,24 +164,24 @@ public class ContentAssistPreference {
boolean enabled = (enabledDot || enabledArrow || enabledDoubleColon || enabledReplaceDotWithArrow); boolean enabled = (enabledDot || enabledArrow || enabledDoubleColon || enabledReplaceDotWithArrow);
assistant.enableAutoActivation(enabled); assistant.enableAutoActivation(enabled);
int delay= store.getInt(AUTOACTIVATION_DELAY); int delay= store.getInt(AUTOACTIVATION_DELAY);
assistant.setAutoActivationDelay(delay); assistant.setAutoActivationDelay(delay);
Color c1= getColor(store, PROPOSALS_FOREGROUND, manager); Color c1= getColor(store, PROPOSALS_FOREGROUND, manager);
assistant.setProposalSelectorForeground(c1); assistant.setProposalSelectorForeground(c1);
Color c2= getColor(store, PROPOSALS_BACKGROUND, manager); Color c2= getColor(store, PROPOSALS_BACKGROUND, manager);
assistant.setProposalSelectorBackground(c2); assistant.setProposalSelectorBackground(c2);
Color c3= getColor(store, PARAMETERS_FOREGROUND, manager); Color c3= getColor(store, PARAMETERS_FOREGROUND, manager);
assistant.setContextInformationPopupForeground(c3); assistant.setContextInformationPopupForeground(c3);
assistant.setContextSelectorForeground(c3); assistant.setContextSelectorForeground(c3);
Color c4= getColor(store, PARAMETERS_BACKGROUND, manager); Color c4= getColor(store, PARAMETERS_BACKGROUND, manager);
assistant.setContextInformationPopupBackground(c4); assistant.setContextInformationPopupBackground(c4);
assistant.setContextSelectorBackground(c4); assistant.setContextSelectorBackground(c4);
enabled= store.getBoolean(AUTOINSERT); enabled= store.getBoolean(AUTOINSERT);
assistant.enableAutoInsert(enabled); assistant.enableAutoInsert(enabled);
@ -189,15 +190,15 @@ public class ContentAssistPreference {
configureCProcessor(assistant, store); configureCProcessor(assistant, store);
} }
private static void changeCProcessor(ContentAssistant assistant, IPreferenceStore store, String key) { private static void changeCProcessor(ContentAssistant assistant, IPreferenceStore store, String key) {
CContentAssistProcessor ccp= getCProcessor(assistant); CContentAssistProcessor ccp= getCProcessor(assistant);
if (ccp == null) if (ccp == null)
return; return;
if ((AUTOACTIVATION_TRIGGERS_DOT.equals(key)) if ((AUTOACTIVATION_TRIGGERS_DOT.equals(key))
|| (AUTOACTIVATION_TRIGGERS_ARROW.equals(key)) || (AUTOACTIVATION_TRIGGERS_ARROW.equals(key))
|| (AUTOACTIVATION_TRIGGERS_DOUBLECOLON.equals(key)) || (AUTOACTIVATION_TRIGGERS_DOUBLECOLON.equals(key))
|| (AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW.equals(key))){ || (AUTOACTIVATION_TRIGGERS_REPLACE_DOT_WITH_ARROW.equals(key))){
configureActivationCharacters(store, ccp); configureActivationCharacters(store, ccp);
} }
@ -217,14 +218,14 @@ public class ContentAssistPreference {
// ccp.allowAddingIncludes(enabled); // ccp.allowAddingIncludes(enabled);
// } // }
} }
/** /**
* Changes the configuration of the given content assistant according to the given property * Changes the configuration of the given content assistant according to the given property
* change event and the given preference store. * change event and the given preference store.
*/ */
public static void changeConfiguration(ContentAssistant assistant, IPreferenceStore store, PropertyChangeEvent event) { public static void changeConfiguration(ContentAssistant assistant, IPreferenceStore store, PropertyChangeEvent event) {
String p= event.getProperty(); String p= event.getProperty();
if ((AUTOACTIVATION_TRIGGERS_DOT.equals(p)) if ((AUTOACTIVATION_TRIGGERS_DOT.equals(p))
|| (AUTOACTIVATION_TRIGGERS_ARROW.equals(p)) || (AUTOACTIVATION_TRIGGERS_ARROW.equals(p))
|| (AUTOACTIVATION_TRIGGERS_DOUBLECOLON.equals(p)) || (AUTOACTIVATION_TRIGGERS_DOUBLECOLON.equals(p))
@ -259,12 +260,12 @@ public class ContentAssistPreference {
boolean enabled= store.getBoolean(PREFIX_COMPLETION); boolean enabled= store.getBoolean(PREFIX_COMPLETION);
assistant.enablePrefixCompletion(enabled); assistant.enablePrefixCompletion(enabled);
} }
changeCProcessor(assistant, store, p); changeCProcessor(assistant, store, p);
} }
private static ContentAssistPreference instance = null; private static ContentAssistPreference instance = null;
private final IPropertyChangeListener propertyListener = new IPropertyChangeListener() { private final IPropertyChangeListener propertyListener = new IPropertyChangeListener() {
@Override @Override
public void propertyChange(PropertyChangeEvent event) { public void propertyChange(PropertyChangeEvent event) {
@ -274,33 +275,33 @@ public class ContentAssistPreference {
} }
} }
}; };
private ContentAssistPreference() { private ContentAssistPreference() {
getPreferences().addPropertyChangeListener(propertyListener); getPreferences().addPropertyChangeListener(propertyListener);
updateOnPreferences(); updateOnPreferences();
} }
public static synchronized ContentAssistPreference getInstance() { public static synchronized ContentAssistPreference getInstance() {
if (instance == null) { if (instance == null) {
instance = new ContentAssistPreference(); instance = new ContentAssistPreference();
} }
return instance; return instance;
} }
private static IPreferenceStore getPreferences() { private static IPreferenceStore getPreferences() {
return CUIPlugin.getDefault().getPreferenceStore(); return CUIPlugin.getDefault().getPreferenceStore();
} }
private synchronized void updateOnPreferences() { private synchronized void updateOnPreferences() {
boolean showCamelCaseMatches = getPreferences().getBoolean(ContentAssistPreference.SHOW_CAMEL_CASE_MATCHES); boolean showCamelCaseMatches = getPreferences().getBoolean(ContentAssistPreference.SHOW_CAMEL_CASE_MATCHES);
ContentAssistMatcherFactory.getInstance().setShowCamelCaseMatches(showCamelCaseMatches); ContentAssistMatcherFactory.getInstance().setShowCamelCaseMatches(showCamelCaseMatches);
} }
private void shutdownInternal() { private void shutdownInternal() {
getPreferences().removePropertyChangeListener(propertyListener); getPreferences().removePropertyChangeListener(propertyListener);
} }
public static synchronized void shutdown() { public static synchronized void shutdown() {
if (instance != null) { if (instance != null) {
instance.shutdownInternal(); instance.shutdownInternal();

View file

@ -124,21 +124,22 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
private static final String TEMPLATE_PARAMETER_PATTERN = "template<{0}> class"; //$NON-NLS-1$; private static final String TEMPLATE_PARAMETER_PATTERN = "template<{0}> class"; //$NON-NLS-1$;
private static final String TYPENAME = "typename"; //$NON-NLS-1$; private static final String TYPENAME = "typename"; //$NON-NLS-1$;
private static final String ELLIPSIS = "..."; //$NON-NLS-1$; private static final String ELLIPSIS = "..."; //$NON-NLS-1$;
private String fPrefix; private String fPrefix = ""; //$NON-NLS-1$
private boolean fGuessArguments;
private List<IBinding> fAvailableElements; private List<IBinding> fAvailableElements;
/** /**
* Default constructor is required (executable extension). * Default constructor is required (executable extension).
*/ */
public DOMCompletionProposalComputer() { public DOMCompletionProposalComputer() {
fPrefix = ""; //$NON-NLS-1$
} }
@Override @Override
protected List<ICompletionProposal> computeCompletionProposals(CContentAssistInvocationContext context, protected List<ICompletionProposal> computeCompletionProposals(CContentAssistInvocationContext context,
IASTCompletionNode completionNode, String prefix) { IASTCompletionNode completionNode, String prefix) {
fPrefix = prefix; fPrefix = prefix;
initializeDefinedElements(context); fGuessArguments = getPreferenceStore().getBoolean(ContentAssistPreference.GUESS_ARGUMENTS);
fAvailableElements = fGuessArguments ? getDefinedElements(context) : Collections.<IBinding>emptyList();
List<ICompletionProposal> proposals = new ArrayList<>(); List<ICompletionProposal> proposals = new ArrayList<>();
if (inPreprocessorDirective(context)) { if (inPreprocessorDirective(context)) {
@ -622,7 +623,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
if (function.getParameters() != null && function.getParameters().length != 0 if (function.getParameters() != null && function.getParameters().length != 0
&& isBeforeParameters(context)) { && isBeforeParameters(context)) {
proposals.add(ParameterGuessingProposal.createProposal(context, fAvailableElements, proposal, proposals.add(ParameterGuessingProposal.createProposal(context, fAvailableElements, proposal,
function, fPrefix)); function, fPrefix, fGuessArguments));
} else { } else {
proposals.add(proposal); proposals.add(proposal);
} }
@ -659,9 +660,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
/** /**
* Initializes the list of variables accessible at the start of the current statement. * Initializes the list of variables accessible at the start of the current statement.
*/ */
private void initializeDefinedElements(CContentAssistInvocationContext context) { private List<IBinding> getDefinedElements(CContentAssistInvocationContext context) {
fAvailableElements = Collections.emptyList();
// Get all variables accessible at the start of the statement. // Get all variables accessible at the start of the statement.
// ex1: int a = foo( // ex1: int a = foo(
// ^ --> We don't want 'a' as a suggestion. // ^ --> We don't want 'a' as a suggestion.
@ -672,7 +671,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
// ^ --> If this offset is used, the only defined name will be "bar(char*)". // ^ --> If this offset is used, the only defined name will be "bar(char*)".
IASTCompletionNode node = context.getCompletionNode(); IASTCompletionNode node = context.getCompletionNode();
if (node == null) if (node == null)
return; return Collections.emptyList();
// Find the enclosing statement at the point of completion. // Find the enclosing statement at the point of completion.
IASTStatement completionStatement = null; IASTStatement completionStatement = null;
@ -687,8 +686,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
} }
} }
if (completionStatement == null) if (completionStatement == null)
return; return Collections.emptyList();
// Get content assist results for an empty prefix at the start of the statement. // Get content assist results for an empty prefix at the start of the statement.
final int statementOffset = getNodeOffset(completionStatement); final int statementOffset = getNodeOffset(completionStatement);
@ -701,7 +699,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
IBinding[] bindings = findBindingsForContextAssist(name, ast); IBinding[] bindings = findBindingsForContextAssist(name, ast);
if (bindings.length == 0) if (bindings.length == 0)
return; return Collections.emptyList();
// Get all variables declared in the translation unit. // Get all variables declared in the translation unit.
final Set<IBinding> declaredVariables = new HashSet<>(); final Set<IBinding> declaredVariables = new HashSet<>();
@ -732,7 +730,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
elementsMap.put(binding.getName(), binding); elementsMap.put(binding.getName(), binding);
} }
} }
fAvailableElements = new ArrayList<>(elementsMap.values()); return new ArrayList<>(elementsMap.values());
} }
private IBinding[] findBindingsForContextAssist(IASTName name, IASTTranslationUnit ast) { private IBinding[] findBindingsForContextAssist(IASTName name, IASTTranslationUnit ast) {

View file

@ -9,6 +9,7 @@
* Andrew McCullough - initial API and implementation * Andrew McCullough - initial API and implementation
* IBM Corporation - general improvement and bug fixes, partial reimplementation * IBM Corporation - general improvement and bug fixes, partial reimplementation
* Mohamed Azab (Mentor Graphics) - Bug 438549. Add mechanism for parameter guessing. * Mohamed Azab (Mentor Graphics) - Bug 438549. Add mechanism for parameter guessing.
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist; package org.eclipse.cdt.internal.ui.text.contentassist;
@ -44,6 +45,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
@ -66,10 +68,11 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
private char[][] fParametersNames; private char[][] fParametersNames;
private IType[] fParametersTypes; private IType[] fParametersTypes;
private List<IBinding> fAssignableElements; private List<IBinding> fAssignableElements;
private final boolean fGuessArguments;
public static ParameterGuessingProposal createProposal(CContentAssistInvocationContext context, public static ParameterGuessingProposal createProposal(CContentAssistInvocationContext context,
List<IBinding> availableElements, CCompletionProposal proposal, IFunction function, List<IBinding> availableElements, CCompletionProposal proposal, IFunction function,
String prefix) { String prefix, boolean guessArguments) {
String replacement = getParametersList(function); String replacement = getParametersList(function);
String fullPrefix = function.getName() + "("; //$NON-NLS-1$ String fullPrefix = function.getName() + "("; //$NON-NLS-1$
int replacementOffset = proposal.getReplacementOffset(); int replacementOffset = proposal.getReplacementOffset();
@ -106,7 +109,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
ParameterGuessingProposal ret = new ParameterGuessingProposal(replacement, replacementOffset, ParameterGuessingProposal ret = new ParameterGuessingProposal(replacement, replacementOffset,
replacementLength, proposal.getImage(), proposal.getDisplayString(), proposal.getIdString(), replacementLength, proposal.getImage(), proposal.getDisplayString(), proposal.getIdString(),
proposal.getRelevance(), context.getViewer(), function, invocationOffset, parseOffset, proposal.getRelevance(), context.getViewer(), function, invocationOffset, parseOffset,
context.getTranslationUnit(), document); context.getTranslationUnit(), document, guessArguments);
ret.setContextInformation(proposal.getContextInformation()); ret.setContextInformation(proposal.getContextInformation());
ret.fFullPrefix = fullPrefix; ret.fFullPrefix = fullPrefix;
ret.fCEditor = getCEditor(context.getEditor()); ret.fCEditor = getCEditor(context.getEditor());
@ -135,9 +138,10 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
public ParameterGuessingProposal(String replacementString, int replacementOffset, int replacementLength, public ParameterGuessingProposal(String replacementString, int replacementOffset, int replacementLength,
Image image, String displayString, String idString, int relevance, ITextViewer viewer, Image image, String displayString, String idString, int relevance, ITextViewer viewer,
IFunction function, int invocationOffset, int parseOffset, ITranslationUnit tu, IFunction function, int invocationOffset, int parseOffset, ITranslationUnit tu,
IDocument document) { IDocument document, boolean guessArguments) {
super(replacementString, replacementOffset, replacementLength, image, displayString, idString, super(replacementString, replacementOffset, replacementLength, image, displayString, idString,
relevance, viewer, function, invocationOffset, parseOffset, tu, document); relevance, viewer, function, invocationOffset, parseOffset, tu, document);
this.fGuessArguments = guessArguments;
} }
/** /**
@ -165,12 +169,14 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
// Initialize necessary fields. // Initialize necessary fields.
fParametersNames = getFunctionParametersNames(fFunctionParameters); fParametersNames = getFunctionParametersNames(fFunctionParameters);
fParametersTypes = getFunctionParametersTypes(fFunctionParameters); fParametersTypes = getFunctionParametersTypes(fFunctionParameters);
try { if (fGuessArguments) {
guessParameters(); try {
} catch (Exception e) { guessParameters();
CUIPlugin.log(e); } catch (Exception e) {
return; CUIPlugin.log(e);
return;
}
} }
int baseOffset = getReplacementOffset(); int baseOffset = getReplacementOffset();
@ -250,7 +256,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
return new Point(fSelectedRegion.getOffset(), fSelectedRegion.getLength()); return new Point(fSelectedRegion.getOffset(), fSelectedRegion.getLength());
} }
private void guessParameters() throws Exception { private void guessParameters() throws CModelException {
int count = fParametersNames.length; int count = fParametersNames.length;
fPositions = new Position[count]; fPositions = new Position[count];
fChoices = new ICompletionProposal[count][]; fChoices = new ICompletionProposal[count][];
@ -269,11 +275,11 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
fPositions[i] = position; fPositions[i] = position;
fChoices[i] = argumentProposals; fChoices[i] = argumentProposals;
} }
updateProposalsPossitions(); updateProposalsPositions();
} }
private void updateProposalsPossitions() throws Exception { private void updateProposalsPositions() {
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
buffer.append(fFullPrefix); buffer.append(fFullPrefix);
setCursorPosition(buffer.length()); setCursorPosition(buffer.length());