eclipse-platform/eclipse.platform.text

Register IReconcilingStrategy with GenericEditor extension point.

angelozerr opened this issue · 1 comments

Todau GenericEditor provides the capability to register IReconciler with org.eclipse.ui.genericeditor.reconcilers

<extension
         point="org.eclipse.ui.genericeditor.reconcilers">
      <reconciler
            class="org.eclipse.lsp4e.operations.folding.LSPFoldingReconciler"
            contentType="org.eclipse.core.runtime.text">.

org.eclipse.lsp4e.operations.folding.LSPFoldingReconciler extends MonoReconciler to benefit with call of reconcile methods with delay to update foldings. The main problem with this strategy that LSPFoldingReconciler create a brackgournd Thread which compute region and dirty region. Another recocniler registered will do that too.

In other words if there are 5 recocniler registered for a given content type, when one file is opened, it will create 5 background Thread and will will do the same process to compute the region and dirty region.

To fix this problem, GenericEditor should manag einternally a Reconciler to provide the capability to register IReconcilingStrategy with extension point:

<extension
         point="org.eclipse.ui.genericeditor.reconcilers">
      <reconcilingStrategy
            class="org.eclipse.lsp4e.operations.folding.LSPFoldingReconcilingStrategy "
            contentType="org.eclipse.core.runtime.text">.

The LSPFoldingReconcilingStrategy requires to get:

  • the IDocument (IReconcilingStrategy#setDocument will give the capability to get the IDocument)
  • the viewer.

To intercept the viewer, we could provide a new interface

public interface ITextViewerLifecycle {

   void install(ITextViewer viewer)

   void uninstall();
}

In other words, the LSPFoldingReconcilingStrategy could looks liks this:

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.reconciler.DirtyRegion;
import org.eclipse.jface.text.reconciler.IReconciler;
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
public class LSPFoldingReconcilingStrategy  implements ITextViewerLifecycle, IReconcilingStrategy {

	private IDocument document;
	private ITextViewer viewer;

	@Override
	public void reconcile(IRegion arg0) {
		// use viewer and document to do some process with delay
	}

	@Override
	public void reconcile(DirtyRegion arg0, IRegion arg1) {
		
	}
	@Override
	public void setDocument(IDocument document) {
		this.document = document;
	}
	@Override
	public void install(ITextViewer viewer) {
		this.viewer = viewer;
	}
	@Override
	public void uninstall() {
		this.viewer = null;
	}
}

The ITextViewerLifecycle should be hosted in JFace because there are a lot of API which could extend it :

I like the idea of ITextViewerLifecycle a lot!
And I like the idea of using it in generic editor and reconciler strategies directly a lot too.