Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2016-11-19 12:02:18 -0500
committerMickael Istria - away until January 11th2017-01-17 10:38:17 -0500
commitaa9773529d30c379ea5c0b25683e698ce2fb4574 (patch)
tree425fa5db3bce7f1c79c5e460290071f135bcfb01 /org.eclipse.ui.genericeditor
parentd77b078388163500961bdab34c0248806eb5c208 (diff)
downloadeclipse.platform.text-aa9773529d30c379ea5c0b25683e698ce2fb4574.tar.gz
eclipse.platform.text-aa9773529d30c379ea5c0b25683e698ce2fb4574.tar.xz
eclipse.platform.text-aa9773529d30c379ea5c0b25683e698ce2fb4574.zip
Bug 251156 - Asynchronous content assist
This provides a new AsyncContentAssistant, performaing computation and presentation of content assist proposals (and related operations) asynchronously whenever possible. Part of this change is also internally allowing the parent ContentAssistant to support multiple IConteantAssistProcessors (although this is not exposed through public API). The AsyncContentAssistant does expose the manipulation of multiple contentAssistProcessors though. Some fields and methods where also made more visible (usually from private to protected or package, to maximize the ability to reuse existing code from the current synchronous framework, in order to make the feature easier to write, and also to provide a consistent experience with aysnc and sync content assist. Change-Id: I3e80c6422eaababc165e955ddeb3539909bfcb9f Signed-off-by: Mickael Istria <mistria@redhat.com>
Diffstat (limited to 'org.eclipse.ui.genericeditor')
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ContentAssistProcessorRegistry.java36
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java19
2 files changed, 35 insertions, 20 deletions
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ContentAssistProcessorRegistry.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ContentAssistProcessorRegistry.java
index a81cecbf8..1ce07367e 100644
--- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ContentAssistProcessorRegistry.java
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ContentAssistProcessorRegistry.java
@@ -17,8 +17,10 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IRegistryChangeEvent;
import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.IStatus;
@@ -32,7 +34,6 @@ import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.PlatformUI;
/**
@@ -80,12 +81,21 @@ public class ContentAssistProcessorRegistry {
/**
* @return whether the referenced contribution should contribute to the current editor.
*/
- public boolean isActive() {
- IEditorInput input = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput();
- IContentTypeManager contentTypeManager= Platform.getContentTypeManager();
- for (IContentType currentContentType : contentTypeManager.findContentTypesFor(input.getName())) {
- if (currentContentType.isKindOf(targetContentType)) {
- return true;
+ public boolean isActive(ITextViewer viewer) {
+ String fileName = null;
+ if (viewer != null && viewer.getDocument() != null) {
+ IPath location = FileBuffers.getTextFileBufferManager().getTextFileBuffer(viewer.getDocument()).getLocation();
+ fileName = location.segment(location.segmentCount() - 1);
+ }
+ if (fileName == null) {
+ fileName = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput().getName();
+ }
+ if (fileName != null) {
+ IContentTypeManager contentTypeManager= Platform.getContentTypeManager();
+ for (IContentType currentContentType : contentTypeManager.findContentTypesFor(fileName)) {
+ if (currentContentType.isKindOf(targetContentType)) {
+ return true;
+ }
}
}
return false;
@@ -93,7 +103,7 @@ public class ContentAssistProcessorRegistry {
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
- if (isActive()) {
+ if (isActive(viewer)) {
return getDelegate().computeCompletionProposals(viewer, offset);
}
return new ICompletionProposal[0];
@@ -101,7 +111,7 @@ public class ContentAssistProcessorRegistry {
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
- if (isActive()) {
+ if (isActive(viewer)) {
return getDelegate().computeContextInformation(viewer, offset);
}
return new IContextInformation[0];
@@ -109,7 +119,7 @@ public class ContentAssistProcessorRegistry {
@Override
public char[] getCompletionProposalAutoActivationCharacters() {
- if (isActive()) {
+ if (isActive(null)) {
return getDelegate().getCompletionProposalAutoActivationCharacters();
}
return null;
@@ -117,7 +127,7 @@ public class ContentAssistProcessorRegistry {
@Override
public char[] getContextInformationAutoActivationCharacters() {
- if (isActive()) {
+ if (isActive(null)) {
return getDelegate().getContextInformationAutoActivationCharacters();
}
return null;
@@ -125,7 +135,7 @@ public class ContentAssistProcessorRegistry {
@Override
public String getErrorMessage() {
- if (isActive()) {
+ if (isActive(null)) {
return getDelegate().getErrorMessage();
}
return null;
@@ -133,7 +143,7 @@ public class ContentAssistProcessorRegistry {
@Override
public IContextInformationValidator getContextInformationValidator() {
- if (isActive()) {
+ if (isActive(null)) {
return getDelegate().getContextInformationValidator();
}
return null;
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java
index 6af35f9d1..61b3c0836 100644
--- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java
@@ -26,6 +26,7 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentPartitioningListener;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.contentassist.AsyncContentAssistant;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContentAssistant;
@@ -49,8 +50,8 @@ public final class ExtensionBasedTextViewerConfiguration extends TextSourceViewe
private ITextEditor editor;
private Set<IContentType> contentTypes;
private IDocument document;
- private ContentAssistant contentAssistant;
- private IContentAssistProcessor contentAssistProcessor;
+ private AsyncContentAssistant contentAssistant;
+ private List<IContentAssistProcessor> processors;
/**
*
@@ -95,13 +96,15 @@ public final class ExtensionBasedTextViewerConfiguration extends TextSourceViewe
@Override
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
ContentAssistProcessorRegistry registry= GenericEditorPlugin.getDefault().getContentAssistProcessorRegistry();
- contentAssistProcessor = new CompositeContentAssistProcessor(registry.getContentAssistProcessors(sourceViewer, getContentTypes()));
- contentAssistant = new ContentAssistant();
+ contentAssistant = new AsyncContentAssistant();
contentAssistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_BELOW);
contentAssistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_REMOVE);
contentAssistant.enableColoredLabels(true);
contentAssistant.enableAutoActivation(true);
- contentAssistant.setContentAssistProcessor(contentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE);
+ this.processors = registry.getContentAssistProcessors(sourceViewer, getContentTypes());
+ for (IContentAssistProcessor processor : this.processors) {
+ contentAssistant.addContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
+ }
if (this.document != null) {
associateTokenContentTypes(this.document);
}
@@ -142,11 +145,13 @@ public final class ExtensionBasedTextViewerConfiguration extends TextSourceViewe
}
private void associateTokenContentTypes(IDocument document) {
- if (contentAssistant == null) {
+ if (contentAssistant == null || this.processors == null) {
return;
}
for (String legalTokenContentType : document.getLegalContentTypes()) {
- contentAssistant.setContentAssistProcessor(this.contentAssistProcessor, legalTokenContentType);
+ for (IContentAssistProcessor processor : this.processors) {
+ contentAssistant.addContentAssistProcessor(processor, legalTokenContentType);
+ }
}
}

Back to the top