1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-30 12:25:35 +02:00

Bug 351076 - Make MAX_DELAY of editor content assist computation configurable

This commit is contained in:
Marko Tomljenovic 2011-07-22 11:13:19 +02:00 committed by Anton Leherbauer
parent 6d8a98e790
commit 0dc841b995
11 changed files with 99 additions and 15 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.ui; singleton:=true
Bundle-Version: 5.3.0.qualifier
Bundle-Version: 5.4.0.qualifier
Bundle-Activator: org.eclipse.cdt.ui.CUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin

View file

@ -3957,6 +3957,9 @@
<key name="stickyOccurrences"/>
<key name="markOverloadedOperatorsOccurrences"/>
<key name="scalability." match="prefix"/>
<key
name="content_assist_proposals_timeout">
</key>
</entry>
</mapping>
<description>

View file

@ -11,7 +11,7 @@
<relativePath>../../pom.xml</relativePath>
</parent>
<version>5.3.0-SNAPSHOT</version>
<version>5.4.0-SNAPSHOT</version>
<artifactId>org.eclipse.cdt.ui</artifactId>
<packaging>eclipse-plugin</packaging>
</project>

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2010 IBM Corporation and others.
* Copyright (c) 2005, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -55,6 +55,7 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.dialogs.PreferencesUtil;
@ -66,6 +67,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener;
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.cdt.internal.ui.text.contentassist.CompletionProposalCategory;
import org.eclipse.cdt.internal.ui.text.contentassist.CompletionProposalComputerRegistry;
import org.eclipse.cdt.internal.ui.util.Messages;
@ -80,11 +82,13 @@ final class CodeAssistAdvancedConfigurationBlock extends OptionsConfigurationBlo
private static final Key PREF_EXCLUDED_CATEGORIES= getCDTUIKey(PreferenceConstants.CODEASSIST_EXCLUDED_CATEGORIES);
private static final Key PREF_CATEGORY_ORDER= getCDTUIKey(PreferenceConstants.CODEASSIST_CATEGORY_ORDER);
private static final Key PREF_PROPOSAL_TIMEOUT= getCDTUIKey(PreferenceConstants.CODEASSIST_PROPOSALS_TIMEOUT);
private static Key[] getAllKeys() {
return new Key[] {
PREF_EXCLUDED_CATEGORIES,
PREF_CATEGORY_ORDER,
PREF_PROPOSAL_TIMEOUT
};
}
@ -355,7 +359,6 @@ final class CodeAssistAdvancedConfigurationBlock extends OptionsConfigurationBlo
layout.marginHeight= 0;
composite.setLayout(layout);
createDefaultLabel(composite, columns);
createDefaultViewer(composite, columns);
createKeysLink(composite, columns);
@ -366,7 +369,9 @@ final class CodeAssistAdvancedConfigurationBlock extends OptionsConfigurationBlo
createSeparateSection(composite);
createFiller(composite, columns);
createTimeoutField(composite, columns);
updateControls();
if (fModel.elements.size() > 0) {
fDefaultViewer.getTable().select(0);
@ -379,6 +384,22 @@ final class CodeAssistAdvancedConfigurationBlock extends OptionsConfigurationBlo
return scrolled;
}
private void createTimeoutField(Composite composite, int columns) {
Composite timeoutComposite= new Composite(composite, SWT.NONE);
GridLayout layout= new GridLayout(3, false);
layout.marginWidth= 0;
layout.marginHeight= 0;
timeoutComposite.setLayout(layout);
GridData gd= new GridData(GridData.FILL, GridData.FILL, true, false, columns, 1);
timeoutComposite.setLayoutData(gd);
PixelConverter pixelConverter= new PixelConverter(composite);
String label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_completionProposalTimeout;
Text textField = addTextField(timeoutComposite, label, PREF_PROPOSAL_TIMEOUT, 0, pixelConverter.convertWidthInCharsToPixels(7));
String toolTip = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_completionProposalTimeoutToolTip;
textField.setToolTipText(toolTip);
}
private void createDefaultLabel(Composite composite, int h_span) {
final ICommandService commandSvc= (ICommandService) PlatformUI.getWorkbench().getAdapter(ICommandService.class);
final Command command= commandSvc.getCommand(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
@ -642,6 +663,26 @@ final class CodeAssistAdvancedConfigurationBlock extends OptionsConfigurationBlo
*/
@Override
protected void validateSettings(Key changedKey, String oldValue, String newValue) {
if (changedKey == null) {
String newVal = getStoredValue(PREF_PROPOSAL_TIMEOUT);
validateSettings(PREF_PROPOSAL_TIMEOUT, null, newVal);
}
else if (changedKey.equals(PREF_PROPOSAL_TIMEOUT)) {
StatusInfo statusInfo = new StatusInfo();
String errMsg = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_completionProposalTimeoutErrMsg;
statusInfo.setError(errMsg);
if (newValue != null) {
try {
long parseLong = Long.parseLong(newValue);
if (parseLong >= 0l) {
statusInfo.setOK();
}
} catch (final NumberFormatException e) {
// do nothing
}
}
fContext.statusChanged(statusInfo);
}
}
/*

View file

@ -52,6 +52,9 @@ public final class PreferencesMessages extends NLS {
public static String CEditorPreferencePage_ContentAssistPage_proposalFilterSelect;
public static String CEditorPreferencePage_ContentAssistPage_completionProposalBackgroundColor;
public static String CEditorPreferencePage_ContentAssistPage_completionProposalForegroundColor;
public static String CEditorPreferencePage_ContentAssistPage_completionProposalTimeout;
public static String CEditorPreferencePage_ContentAssistPage_completionProposalTimeoutErrMsg;
public static String CEditorPreferencePage_ContentAssistPage_completionProposalTimeoutToolTip;
public static String CEditorPreferencePage_ContentAssistPage_parameterBackgroundColor;
public static String CEditorPreferencePage_ContentAssistPage_parameterForegroundColor;
public static String CEditorPreferencePage_ContentAssistPage_sortingSection_title;

View file

@ -38,6 +38,9 @@ CEditorPreferencePage_ContentAssistPage_autoActivationDelay=Dela&y (ms)
CEditorPreferencePage_ContentAssistPage_proposalFilterSelect=Completion Proposal Filter:
CEditorPreferencePage_ContentAssistPage_completionProposalBackgroundColor=Completion proposal background
CEditorPreferencePage_ContentAssistPage_completionProposalForegroundColor=Completion proposal foreground
CEditorPreferencePage_ContentAssistPage_completionProposalTimeoutErrMsg=Time must be >= 0 milli seconds
CEditorPreferencePage_ContentAssistPage_completionProposalTimeout=Timeout for each proposal kind (ms):
CEditorPreferencePage_ContentAssistPage_completionProposalTimeoutToolTip=If a proposal kind has consumed more time for computation than defined here\nit is assumed that the computer is faulty.\nIn this case a dialog is showing up telling an appropriate message to the user.
CEditorPreferencePage_ContentAssistPage_parameterBackgroundColor=Parameter hint background
CEditorPreferencePage_ContentAssistPage_parameterForegroundColor=Parameter hint foreground
CEditorPreferencePage_ContentAssistPage_sortingSection_title=Sorting and Filtering

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation and others.
* Copyright (c) 2005, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -34,6 +34,7 @@ import org.eclipse.jface.text.contentassist.IContextInformation;
import org.osgi.framework.Bundle;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext;
import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer;
@ -70,13 +71,6 @@ final class CompletionProposalComputerDescriptor {
* core's {@link PerformanceStats} service.
*/
private static final boolean MEASURE_PERFORMANCE= PerformanceStats.isEnabled(PERFORMANCE_EVENT);
/**
* Independently of the {@link PerformanceStats} service, any operation that takes longer than
* {@value} milliseconds will be flagged as an violation. This timeout does not apply to the
* first invocation, as it may take longer due to plug-in initialization etc. See also
* {@link #fIsReportingDelay}.
*/
private static final long MAX_DELAY= 5000;
/* log constants */
private static final String COMPUTE_COMPLETION_PROPOSALS= "computeCompletionProposals()"; //$NON-NLS-1$
@ -113,7 +107,7 @@ final class CompletionProposalComputerDescriptor {
/** The first error message in the most recent operation, or <code>null</code>. */
private String fLastError;
/**
* Tells whether to inform the user when <code>MAX_DELAY</code> has been exceeded.
* Tells whether to inform the user when the value of <code>getMaxDelay()</code> has been exceeded.
* We start timing execution after the first session because the first may take
* longer due to plug-in activation and initialization.
*/
@ -463,13 +457,32 @@ final class CompletionProposalComputerDescriptor {
if (fIsReportingDelay) {
long current= System.currentTimeMillis();
if (current - fStart > MAX_DELAY) {
if (current - fStart > getMaxDelay()) {
IStatus status= createPerformanceStatus(operation);
fRegistry.informUser(this, status);
}
}
}
/**
* Independently of the {@link PerformanceStats} service, any operation that takes longer than
* the milliseconds returned by this method will be flagged as an violation. This timeout does
* not apply to the first invocation, as it may take longer due to plug-in initialization etc.
* See also {@link #fIsReportingDelay}.
* <p>
* The max duration is stored in the preference {@link ContentAssistPreference#PROPOSALS_TIMEOUT}
*
* @return the max duration (ms) a proposal computer is allowed to compute until it is
* assumed to be buggy and will be disabled.<br>
* Is always > 0
*/
private long getMaxDelay() {
long timeout = CUIPlugin.getDefault().getPreferenceStore().getLong(PreferenceConstants.CODEASSIST_PROPOSALS_TIMEOUT);
if (timeout <= 0L)
return Long.MAX_VALUE;
return timeout;
}
private IStatus createExceptionStatus(InvalidRegistryObjectException x) {
// extension has become invalid - log & disable
String blame= createBlameMessage();

View file

@ -40,6 +40,8 @@ public class ContentAssistPreference {
public final static String AUTOACTIVATION_DELAY= "content_assist_autoactivation_delay"; //$NON-NLS-1$
/** Preference key for content assist timeout delay (unused) */
public final static String TIMEOUT_DELAY= "content_assist_timeout_delay"; //$NON-NLS-1$
/** Preference key for completion proposal timeout */
public final static String PROPOSALS_TIMEOUT= PreferenceConstants.CODEASSIST_PROPOSALS_TIMEOUT;
/** Preference key for content assist proposal color */
public final static String PROPOSALS_FOREGROUND= PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND;
/** Preference key for content assist proposal color */

View file

@ -1123,6 +1123,16 @@ public class PreferenceConstants {
public final static String CODEASSIST_PROPOSALS_FOREGROUND= "content_assist_proposals_foreground"; //$NON-NLS-1$
/**
* A named preference that holds the duration (in milli seconds) a content proposal may compute
* until it is assumed that the proposal computer has a problem and should be disabled.
* <p>
* Value is of type <code>long</code>.
*
* @since 5.4
*/
public final static String CODEASSIST_PROPOSALS_TIMEOUT= "content_assist_proposals_timeout"; //$NON-NLS-1$
/**
* A named preference that holds the background color used for parameter hints.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
@ -1960,6 +1970,8 @@ public class PreferenceConstants {
store.setDefault(PreferenceConstants.CODEASSIST_EXCLUDED_CATEGORIES, "org.eclipse.cdt.ui.textProposalCategory\0"); //$NON-NLS-1$
store.setDefault(PreferenceConstants.CODEASSIST_CATEGORY_ORDER, "org.eclipse.cdt.ui.parserProposalCategory:65539\0org.eclipse.cdt.ui.textProposalCategory:65541\0org.eclipse.cdt.ui.templateProposalCategory:2\0org.eclipse.cdt.ui.helpProposalCategory:5\0"); //$NON-NLS-1$
store.setDefault(PreferenceConstants.CODEASSIST_PROPOSALS_TIMEOUT, 5000);
setDefaultAndFireEvent(
store,
PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View file

@ -44,6 +44,13 @@
<td headers="option"><strong>Down</strong></td>
<td headers="description">Moves the selected proposal item down in the cycling list.</td>
</tr>
<tr valign="top">
<td headers="option"><strong>Timeout for each proposal kind (ms)</strong></td>
<td headers="description">Specifies the number of milliseconds a code completion proposal kind is allowed to compute
proposals. If it takes more time then it is assumed that this proposal kind is faulty.
In this case a dialog is opened and an appropriate message is shown to the user<br>If the value is 0 each completion
proposal can compute as long as it needs to before being assumed to be faulty.</td>
</tr>
</tbody>
</table>