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:
parent
86dabd3d00
commit
70fe6cbbde
6 changed files with 70 additions and 57 deletions
|
@ -12,6 +12,7 @@
|
|||
* Kirk Beitz (Nokia)
|
||||
* Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
|
||||
* Thomas Corbat
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
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.BOOLEAN, ContentAssistPreference.AUTOINSERT));
|
||||
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.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOT));
|
||||
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;
|
||||
addCheckBox(insertionGroup, label, ContentAssistPreference.PREFIX_COMPLETION, 0);
|
||||
|
||||
label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_guessArguments;
|
||||
addCheckBox(insertionGroup, label, ContentAssistPreference.GUESS_ARGUMENTS, 0);
|
||||
|
||||
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
|
||||
// sorting and filtering
|
||||
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);
|
||||
|
||||
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
|
||||
|
@ -181,6 +186,7 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage {
|
|||
|
||||
store.setDefault(ContentAssistPreference.AUTOINSERT, true);
|
||||
store.setDefault(ContentAssistPreference.PREFIX_COMPLETION, true);
|
||||
store.setDefault(ContentAssistPreference.GUESS_ARGUMENTS, true);
|
||||
store.setDefault(ContentAssistPreference.ORDER_PROPOSALS, false);
|
||||
store.setDefault(ContentAssistPreference.PROPOSALS_FILTER,
|
||||
ProposalFilterPreferencesUtil.getProposalFilternamesAsString());
|
||||
|
|
|
@ -42,6 +42,7 @@ public final class PreferencesMessages extends NLS {
|
|||
public static String CEditorPreferencePage_ContentAssistPage_insertionGroupTitle;
|
||||
public static String CEditorPreferencePage_ContentAssistPage_insertSingleProposalAutomatically;
|
||||
public static String CEditorPreferencePage_ContentAssistPage_insertCommonProposalAutomatically;
|
||||
public static String CEditorPreferencePage_ContentAssistPage_guessArguments;
|
||||
public static String CEditorPreferencePage_ContentAssistPage_showProposalsInAlphabeticalOrder;
|
||||
public static String CEditorPreferencePage_ContentAssistPage_showCamelCaseMatches;
|
||||
public static String CEditorPreferencePage_ContentAssistPage_autoActivationGroupTitle;
|
||||
|
|
|
@ -26,8 +26,9 @@ CEditorPreferencePage_colors=Synta&x
|
|||
#CEditorPreferencePage_ContentAssistPage_searchGroupCurrentFileOption=S&earch current file and included files
|
||||
#CEditorPreferencePage_ContentAssistPage_searchGroupCurrentProjectOption=Search current &project
|
||||
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_guessArguments=&Fill function arguments and show guessed arguments
|
||||
CEditorPreferencePage_ContentAssistPage_showProposalsInAlphabeticalOrder=Present proposals in a&lphabetical order
|
||||
CEditorPreferencePage_ContentAssistPage_showCamelCaseMatches=Show ca&mel case matches
|
||||
CEditorPreferencePage_ContentAssistPage_autoActivationGroupTitle=Auto-Activation
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
* Anton Leherbauer (Wind River Systems)
|
||||
* Kirk Beitz (Nokia)
|
||||
* Thomas Corbat (IFS)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.text.contentassist;
|
||||
|
||||
|
|
|
@ -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 TYPENAME = "typename"; //$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;
|
||||
|
||||
/**
|
||||
* Default constructor is required (executable extension).
|
||||
*/
|
||||
public DOMCompletionProposalComputer() {
|
||||
fPrefix = ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ICompletionProposal> computeCompletionProposals(CContentAssistInvocationContext context,
|
||||
IASTCompletionNode completionNode, String prefix) {
|
||||
fPrefix = prefix;
|
||||
initializeDefinedElements(context);
|
||||
fGuessArguments = getPreferenceStore().getBoolean(ContentAssistPreference.GUESS_ARGUMENTS);
|
||||
fAvailableElements = fGuessArguments ? getDefinedElements(context) : Collections.<IBinding>emptyList();
|
||||
List<ICompletionProposal> proposals = new ArrayList<>();
|
||||
|
||||
if (inPreprocessorDirective(context)) {
|
||||
|
@ -622,7 +623,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
if (function.getParameters() != null && function.getParameters().length != 0
|
||||
&& isBeforeParameters(context)) {
|
||||
proposals.add(ParameterGuessingProposal.createProposal(context, fAvailableElements, proposal,
|
||||
function, fPrefix));
|
||||
function, fPrefix, fGuessArguments));
|
||||
} else {
|
||||
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.
|
||||
*/
|
||||
private void initializeDefinedElements(CContentAssistInvocationContext context) {
|
||||
fAvailableElements = Collections.emptyList();
|
||||
|
||||
private List<IBinding> getDefinedElements(CContentAssistInvocationContext context) {
|
||||
// Get all variables accessible at the start of the statement.
|
||||
// ex1: int a = foo(
|
||||
// ^ --> 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*)".
|
||||
IASTCompletionNode node = context.getCompletionNode();
|
||||
if (node == null)
|
||||
return;
|
||||
return Collections.emptyList();
|
||||
|
||||
// Find the enclosing statement at the point of completion.
|
||||
IASTStatement completionStatement = null;
|
||||
|
@ -687,8 +686,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
}
|
||||
}
|
||||
if (completionStatement == null)
|
||||
return;
|
||||
|
||||
return Collections.emptyList();
|
||||
|
||||
// Get content assist results for an empty prefix at the start of the statement.
|
||||
final int statementOffset = getNodeOffset(completionStatement);
|
||||
|
@ -701,7 +699,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
IBinding[] bindings = findBindingsForContextAssist(name, ast);
|
||||
|
||||
if (bindings.length == 0)
|
||||
return;
|
||||
return Collections.emptyList();
|
||||
|
||||
// Get all variables declared in the translation unit.
|
||||
final Set<IBinding> declaredVariables = new HashSet<>();
|
||||
|
@ -732,7 +730,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
elementsMap.put(binding.getName(), binding);
|
||||
}
|
||||
}
|
||||
fAvailableElements = new ArrayList<>(elementsMap.values());
|
||||
return new ArrayList<>(elementsMap.values());
|
||||
}
|
||||
|
||||
private IBinding[] findBindingsForContextAssist(IASTName name, IASTTranslationUnit ast) {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* Andrew McCullough - initial API and implementation
|
||||
* IBM Corporation - general improvement and bug fixes, partial reimplementation
|
||||
* Mohamed Azab (Mentor Graphics) - Bug 438549. Add mechanism for parameter guessing.
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
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.IParameter;
|
||||
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.ui.CUIPlugin;
|
||||
|
||||
|
@ -66,10 +68,11 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
|||
private char[][] fParametersNames;
|
||||
private IType[] fParametersTypes;
|
||||
private List<IBinding> fAssignableElements;
|
||||
private final boolean fGuessArguments;
|
||||
|
||||
public static ParameterGuessingProposal createProposal(CContentAssistInvocationContext context,
|
||||
List<IBinding> availableElements, CCompletionProposal proposal, IFunction function,
|
||||
String prefix) {
|
||||
String prefix, boolean guessArguments) {
|
||||
String replacement = getParametersList(function);
|
||||
String fullPrefix = function.getName() + "("; //$NON-NLS-1$
|
||||
int replacementOffset = proposal.getReplacementOffset();
|
||||
|
@ -106,7 +109,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
|||
ParameterGuessingProposal ret = new ParameterGuessingProposal(replacement, replacementOffset,
|
||||
replacementLength, proposal.getImage(), proposal.getDisplayString(), proposal.getIdString(),
|
||||
proposal.getRelevance(), context.getViewer(), function, invocationOffset, parseOffset,
|
||||
context.getTranslationUnit(), document);
|
||||
context.getTranslationUnit(), document, guessArguments);
|
||||
ret.setContextInformation(proposal.getContextInformation());
|
||||
ret.fFullPrefix = fullPrefix;
|
||||
ret.fCEditor = getCEditor(context.getEditor());
|
||||
|
@ -135,9 +138,10 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
|||
public ParameterGuessingProposal(String replacementString, int replacementOffset, int replacementLength,
|
||||
Image image, String displayString, String idString, int relevance, ITextViewer viewer,
|
||||
IFunction function, int invocationOffset, int parseOffset, ITranslationUnit tu,
|
||||
IDocument document) {
|
||||
IDocument document, boolean guessArguments) {
|
||||
super(replacementString, replacementOffset, replacementLength, image, displayString, idString,
|
||||
relevance, viewer, function, invocationOffset, parseOffset, tu, document);
|
||||
this.fGuessArguments = guessArguments;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -166,12 +170,14 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
|||
fParametersNames = getFunctionParametersNames(fFunctionParameters);
|
||||
fParametersTypes = getFunctionParametersTypes(fFunctionParameters);
|
||||
|
||||
if (fGuessArguments) {
|
||||
try {
|
||||
guessParameters();
|
||||
} catch (Exception e) {
|
||||
CUIPlugin.log(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int baseOffset = getReplacementOffset();
|
||||
String replacement = getReplacementString();
|
||||
|
@ -250,7 +256,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
|||
return new Point(fSelectedRegion.getOffset(), fSelectedRegion.getLength());
|
||||
}
|
||||
|
||||
private void guessParameters() throws Exception {
|
||||
private void guessParameters() throws CModelException {
|
||||
int count = fParametersNames.length;
|
||||
fPositions = new Position[count];
|
||||
fChoices = new ICompletionProposal[count][];
|
||||
|
@ -269,11 +275,11 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal {
|
|||
fPositions[i] = position;
|
||||
fChoices[i] = argumentProposals;
|
||||
}
|
||||
updateProposalsPossitions();
|
||||
updateProposalsPositions();
|
||||
}
|
||||
|
||||
private void updateProposalsPossitions() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
private void updateProposalsPositions() {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append(fFullPrefix);
|
||||
setCursorPosition(buffer.length());
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue