Fix links in live hovers in VSCode
This commit is contained in:
@@ -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);
|
||||
@@ -35,13 +37,10 @@ public class JavadocHoverLinkHandler implements IDelegateCommandHandler {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user