Skip to content

Commit 1e4ba96

Browse files
committed
fix: try
1 parent bc39372 commit 1e4ba96

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

plugin/src/software/aws/toolkits/eclipse/amazonq/util/AutoTriggerPartListener.java

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
package software.aws.toolkits.eclipse.amazonq.util;
5-
65
import static software.aws.toolkits.eclipse.amazonq.util.QEclipseEditorUtils.getActiveTextEditor;
6+
import static software.aws.toolkits.eclipse.amazonq.util.QEclipseEditorUtils.getActiveTextViewer;
77

88
import org.eclipse.jface.text.IDocument;
99
import org.eclipse.jface.text.IDocumentListener;
@@ -25,16 +25,43 @@ public AutoTriggerPartListener(final T docListener) {
2525
@Override
2626
public void partActivated(final IWorkbenchPartReference partRef) {
2727
var part = partRef.getPart(false);
28-
if (!(part instanceof ITextEditor)) {
28+
boolean isEditor = part instanceof ITextEditor;
29+
if (isEditor) {
30+
ITextEditor editor = (ITextEditor) part;
31+
32+
// We should only have at most one listener listening to one document
33+
// at any given moment. Therefore it would be acceptable to override the
34+
// listener
35+
// This is also assuming an active part cannot be activated again.
36+
attachDocumentListenerAndUpdateActiveDocument(editor);
2937
return;
3038
}
31-
ITextEditor editor = (ITextEditor) part;
3239

33-
// We should only have at most one listener listening to one document
34-
// at any given moment. Therefore it would be acceptable to override the
35-
// listener
36-
// This is also assuming an active part cannot be activated again.
37-
attachDocumentListenerAndUpdateActiveDocument(editor);
40+
/**
41+
* When users use ADT plugin and connect to SAP server, the file opened is a customized editor defined by SAP package.
42+
* com.sap.adt.programs.ui.internal.programs.editors.ProgramEditor, which cause above logic not executed, inline listener is not attached hence inline auto trigger is broken.
43+
* Here is a monkey patch to fix the issue based on how we currently instrument inline auto trigger.
44+
* We might need to add different class names if we see more variants of such editor/file showing.
45+
*/
46+
boolean isProgramEditor = part.getClass().getName().contains("ProgramEditor");
47+
if (isEditor) {
48+
ITextEditor editor = (ITextEditor) part;
49+
50+
// We should only have at most one listener listening to one document
51+
// at any given moment. Therefore it would be acceptable to override the
52+
// listener
53+
// This is also assuming an active part cannot be activated again.
54+
attachDocumentListenerAndUpdateActiveDocument(editor);
55+
} else if (isProgramEditor) {
56+
ITextEditor e = getActiveTextEditor();
57+
var viewer = getActiveTextViewer(e);
58+
if (viewer != null) {
59+
var document = viewer.getDocument();
60+
if (document != null) {
61+
attachDocumentListenerAndUpdateActiveDocument(document);
62+
}
63+
}
64+
}
3865
}
3966

4067
@Override
@@ -48,8 +75,12 @@ public void partDeactivated(final IWorkbenchPartReference partRef) {
4875

4976
private void attachDocumentListenerAndUpdateActiveDocument(final ITextEditor editor) {
5077
var document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
78+
attachDocumentListenerAndUpdateActiveDocument(document);
79+
}
80+
81+
private void attachDocumentListenerAndUpdateActiveDocument(final IDocument document) {
5182
document.addDocumentListener(docListener);
52-
activeDocument = document;
83+
setActiveDocument(document);
5384
}
5485

5586
private void detachDocumentListenerFromLastActiveDocument() {

0 commit comments

Comments
 (0)