Skip to content

Commit

Permalink
Error while hovering over Maven artifacts / broken eclipse-lsp4e#820
Browse files Browse the repository at this point in the history
Issue: eclipse-lsp4e#820

Signed-off-by: Victor Rubezhny <[email protected]>
  • Loading branch information
vrubezhny committed Nov 12, 2023
1 parent d342047 commit 66929ca
Showing 1 changed file with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2020 Red Hat Inc. and others.
* Copyright (c) 2016, 2023 Red Hat Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand Down Expand Up @@ -91,21 +91,21 @@ 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 = 20 + (safeEvaluate(browser, "return document.body.scrollWidth;") instanceof Double evaluated ? evaluated : 0); //$NON-NLS-1$
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 = safeEvaluate(browser, "return document.body.scrollHeight;") instanceof Double evaluated ? evaluated : 0; //$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();
}

width = Double.valueOf(width * 1.5);
Expand All @@ -125,6 +125,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 66929ca

Please sign in to comment.