Skip to content

Commit

Permalink
Error while hovering over Maven artifacts / broken eclipse#820
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Rubezhny <[email protected]>
  • Loading branch information
vrubezhny committed Nov 11, 2023
1 parent d342047 commit 3474a5b
Showing 1 changed file with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,22 @@ protected void createContent(Composite parent) {
@Nullable
Point constraints = getSizeConstraints();
Point hint = computeSizeHint();

setSize(hint.x, hint.y);
browser.execute("document.getElementsByTagName(\"html\")[0].style.whiteSpace = \"nowrap\""); //$NON-NLS-1$
Double width = 20 + (Double) browser.evaluate("return document.body.scrollWidth;"); //$NON-NLS-1$

safeExecute(browser, "document.getElementsByTagName(\"html\")[0].style.whiteSpace = \"nowrap\""); //$NON-NLS-1$
Double width = (Double) safeEvaluate(browser, "return document.body.scrollWidth;"); //$NON-NLS-1$
width = 20 + (width != null ? width : 0);
setSize(width.intValue(), hint.y);
browser.execute("document.getElementsByTagName(\"html\")[0].style.whiteSpace = \"normal\""); //$NON-NLS-1$
Double height = (Double) browser.evaluate("return document.body.scrollHeight;"); //$NON-NLS-1$
Object marginTop = browser.evaluate("return window.getComputedStyle(document.body).marginTop;"); //$NON-NLS-1$
Object marginBottom = browser.evaluate("return getComputedStyle(document.body).marginBottom;"); //$NON-NLS-1$

safeExecute(browser, "document.getElementsByTagName(\"html\")[0].style.whiteSpace = \"normal\""); //$NON-NLS-1$
Double height = (Double) safeEvaluate(browser, "return document.body.scrollHeight;"); //$NON-NLS-1$
Object marginTop = safeEvaluate(browser, "return window.getComputedStyle(document.body).marginTop;"); //$NON-NLS-1$
Object marginBottom = safeEvaluate(browser, "return window.getComputedStyle(document.body).marginBottom;"); //$NON-NLS-1$
if (Platform.getPreferencesService().getBoolean(EditorsUI.PLUGIN_ID,
AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE, true,
null)) {
FontData[] fontDatas = JFaceResources.getDialogFont().getFontData();
height = fontDatas[0].getHeight() + height;
height = fontDatas[0].getHeight() + (height != null ? height : 0);
}

width = Double.valueOf(width * 1.5);
Expand All @@ -125,6 +126,24 @@ protected void createContent(Composite parent) {
b.setJavascriptEnabled(true);
}

private static Object safeEvaluate(Browser browser, String expression) {
try {
return browser.evaluate(expression);
} catch (Throwable ex) {
LanguageServerPlugin.logError(ex);
}
return null;
}

private static boolean safeExecute(Browser browser, String expression) {
try {
return browser.execute(expression);
} catch (Throwable ex) {
LanguageServerPlugin.logError(ex);
}
return false;
}

@Override
public void setInput(Object input) {
if (input instanceof String html) {
Expand Down

0 comments on commit 3474a5b

Please sign in to comment.