Closed angelozerr closed 1 year ago
ITextEditorAware API allows to inject an instance of ITextEditor.
I create this API because I need it for https://github.com/eclipse-platform/eclipse.platform.ui/issues/877
More I think this API can be very helpfull for generic editor. My idea is when generic editor creates a custom reconciler for instance, it check that the instanciated class implemented ITextEditorAware and in this case it set the editor to the contribution here https://github.com/eclipse-platform/eclipse.platform.text/blob/1900585152bdd052e3c38e2da2440b3405fb36ee/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericContentTypeRelatedExtension.java#L59
With this code:
@SuppressWarnings("unchecked")
public T createDelegate(ITextEditor editor) {
try {
T delegateInstance = (T) extension.createExecutableExtension(CLASS_ATTRIBUTE);
if (delegateInstance instanceof ITextEditorAware) {
((ITextEditorAware) delegateInstance).setEditor(editor);
}
return delegateInstance;
} catch (CoreException e) {
GenericEditorPlugin.getDefault().getLog()
.log(new Status(IStatus.ERROR, GenericEditorPlugin.BUNDLE_ID, e.getMessage(), e));
}
return null;
}
A good usecase is in LSP4e https://github.com/eclipse/lsp4e/blob/c6859853bd37c5ae70e9ee9ba43495ff28d668d3/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/completion/LSContentAssistProcessor.java#L197
Here the required editor is get with a static method, by getting the current activate editor. It should be cleaner to do like this:
public class LSContentAssistProcessor implements IContentAssistProcessor, ITextEditorAware {
private TextEditor editor;
@Override
public void setEditor(ITextEditor editor) {
this.editor = editor;
}
...
}
@mickaelistria do you like this idea?
Ok I have updated my PR to use ITextEditorAware with generic editor. It will opens the door to access to the generic editor in any contribution.
The main idea is to avoid getting the activated editor to get the editor in each contribution. I see that:
@mickaelistria here a concrete sample in the PR https://github.com/eclipse/tm4e/pull/461 which uses ITextEditorAware to have cleaner code in TM4e language configuration
https://github.com/eclipse-pde/eclipse.pde/pull/402 should fix further issues.
Is this PR still relevant?
This repository was merged with https://github.com/eclipse-platform/eclipse.platform.ui if your pull-request is still relevant please rebase the code and push it to the new repository.
ITextEditorAware API to inject ITextEditor.
Signed-off-by: azerr azerr@redhat.com