Skip to content

Commit

Permalink
Fix links in live hovers in VSCode
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Jun 13, 2024
1 parent f14172d commit 5a68303
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@
*******************************************************************************/
package org.springframework.tooling.jdt.ls.extension;

import java.lang.reflect.Method;
import java.net.URI;
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.ls.core.internal.javadoc.JavaElementLinks;
import org.eclipse.jdt.ls.core.internal.IDelegateCommandHandler;
import org.eclipse.jdt.ls.core.internal.JDTUtils;
import org.eclipse.lsp4j.Location;
import org.springframework.tooling.jdt.ls.commons.java.JavaData;

@SuppressWarnings("restriction")
public class JavadocHoverLinkHandler implements IDelegateCommandHandler {

@SuppressWarnings("unchecked")
@Override
public Object executeCommand(String commandId, List<Object> arguments, IProgressMonitor monitor) throws Exception {
Map<String, Object> obj = (Map<String, Object>) arguments.get(0);
Expand All @@ -35,13 +37,10 @@ public Object executeCommand(String commandId, List<Object> arguments, IProgress
if (element != null) {
// Bug in JDT server one '(' not encoded while everything else in the query is
// encoded
try {
Class<?> clazz = getClass().getClassLoader().loadClass("org.eclipse.jdt.internal.ui.viewsupport.CoreJavaElementLinks");
Method method = clazz.getDeclaredMethod("createURI", String.class, IJavaElement.class);
return method.invoke(null, null, element);
} catch (Exception e) {
return JavaElementLinks.createURI(null, element).replace("(", "%28");
}
Location locationToElement = JDTUtils.toLocation(element);
if (locationToElement != null) {
return (locationToElement.getUri() + "#" + (locationToElement.getRange().getStart().getLine() + 1)).replace("(", "%28");
}
}
} catch (Exception e) {
JdtLsExtensionPlugin.getInstance().getLog().error("Failed to compute java data for " + bindingKey + " in project " + uri, e);
Expand Down

0 comments on commit 5a68303

Please sign in to comment.