Eclipse IntroURL label parameter for LocationLink URI

This commit is contained in:
BoykoAlex
2020-05-11 13:05:28 -04:00
parent ab829de9a4
commit e1025d22ee
2 changed files with 14 additions and 4 deletions

View File

@@ -33,6 +33,7 @@ import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.ILocalVariable;
import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jdt.ui.JavaElementLabels;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.preference.IPreferenceStore;
@@ -132,6 +133,7 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La
private final JavaFluxSearch javaFluxSearch = new JavaFluxSearch(Logger.forEclipsePlugin(LanguageServerCommonsActivator::getInstance), javaData);
private final TypeHierarchy typeHierarchy = new TypeHierarchy(Logger.forEclipsePlugin(LanguageServerCommonsActivator::getInstance), javaData);
private final JavaCodeCompletion codeComplete = new JavaCodeCompletion();
private final JavaElementLabelProvider javaLabelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_POST_QUALIFIED);
private static final String ANNOTION_TYPE_ID = "org.springframework.tooling.bootinfo";
@@ -478,7 +480,8 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La
IJavaProject project = element.getJavaProject() == null ? ResourceUtils.getJavaProject(projectUri) : element.getJavaProject();
if (project != null) {
Location location = new Location();
location.setUri(Utils.eclipseIntroUri(project.getElementName(), params.getBindingKey()).toString());
String label = javaLabelProvider.getText(element);
location.setUri(Utils.eclipseIntroUri(project.getElementName(), params.getBindingKey(), label).toString());
// Set the range because LocationLink needs it to be non-null. The target range
// would highlighted by the eclipse intro URL navigation anyway
location.setRange(new Range());

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2019 Pivotal, Inc.
* Copyright (c) 2018, 2020 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -31,11 +31,13 @@ import org.eclipse.ui.PlatformUI;
@SuppressWarnings("restriction")
public class Utils {
private static final String UTF8 = "UTF8";
private static final String URL_PREFIX = "http://org.eclipse.ui.intro/execute?command=";
private static final String EQUALS = "=";
private static final String PARAMETERS_SEPARATOR = ",";
private static final String PARAMETERS_START = "(";
private static final String PARAMETERS_END = ")";
private static final String LABEL_PARAMETER_PREFIX = "&label=";
private static final String JAVA_ELEMENT_COMMAND = "org.springframework.tooling.ls.eclipse.commons.commands.OpenJavaElementInEditor";
private static final String BINDING_KEY_PARAMETER_ID = "bindingKey";
@@ -118,7 +120,7 @@ public class Utils {
return null;
}
public static URI eclipseIntroUri(String projectName, String bindingKey) throws UnsupportedEncodingException {
public static URI eclipseIntroUri(String projectName, String bindingKey, String label) throws UnsupportedEncodingException {
StringBuilder paramBuilder = new StringBuilder(JAVA_ELEMENT_COMMAND);
paramBuilder.append(PARAMETERS_START);
paramBuilder.append(BINDING_KEY_PARAMETER_ID);
@@ -133,7 +135,12 @@ public class Utils {
paramBuilder.append(PARAMETERS_END);
StringBuilder urlBuilder = new StringBuilder(URL_PREFIX);
urlBuilder.append(URLEncoder.encode(paramBuilder.toString(), "UTF8"));
urlBuilder.append(URLEncoder.encode(paramBuilder.toString(), UTF8));
if (label != null) {
urlBuilder.append(LABEL_PARAMETER_PREFIX);
urlBuilder.append(URLEncoder.encode(label, UTF8));
}
return URI.create(urlBuilder.toString());
}