Skip to content

Commit

Permalink
Issue eclipse#63 - getDocument(ITextEditor) incorrectly assumes an
Browse files Browse the repository at this point in the history
implementation of AbstractTextEditor
  • Loading branch information
mickaelistria committed Feb 1, 2022
1 parent f646fd8 commit 30e58bc
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions org.eclipse.lsp4e/src/org/eclipse/lsp4e/LSPEclipseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ public static void open(String uri, IWorkbenchPage page, Range optionalRange) {
}
} else {
openFileLocationInEditor(uri, page, optionalRange);
}
}
}

protected static void openIntroURL(final String uri) {
Expand Down Expand Up @@ -604,15 +604,21 @@ protected static void openFileLocationInEditor(String uri, IWorkbenchPage page,
}

public static IDocument getDocument(ITextEditor editor) {
try {
Method getSourceViewerMethod= AbstractTextEditor.class.getDeclaredMethod("getSourceViewer"); //$NON-NLS-1$
getSourceViewerMethod.setAccessible(true);
ITextViewer viewer = (ITextViewer) getSourceViewerMethod.invoke(editor);
return viewer.getDocument();
} catch (Exception ex) {
LanguageServerPlugin.logError(ex);
return null;
IDocument res = getDocument(editor.getEditorInput());
if (res != null) {
return res;
}
if (editor instanceof AbstractTextEditor) {
try {
Method getSourceViewerMethod= AbstractTextEditor.class.getDeclaredMethod("getSourceViewer"); //$NON-NLS-1$
getSourceViewerMethod.setAccessible(true);
ITextViewer viewer = (ITextViewer) getSourceViewerMethod.invoke(editor);
return viewer.getDocument();
} catch (Exception ex) {
LanguageServerPlugin.logError(ex);
}
}
return null;
}

public static IDocument getDocument(IEditorInput editorInput) {
Expand Down

0 comments on commit 30e58bc

Please sign in to comment.