PT #163527410: Don't load source for Eclipse. Ask JDT LS for locations.

This commit is contained in:
BoykoAlex
2019-02-04 18:48:40 -05:00
parent 5bb448b0a0
commit 7fe0d75412
19 changed files with 245 additions and 56 deletions

View File

@@ -104,14 +104,6 @@
<extension
point="org.eclipse.ui.handlers">
<handler
class="org.springframework.tooling.boot.ls.commands.OpenJavaElementInEditor"
commandId="org.springframework.tooling.boot.ls.OpenJavaElement">
</handler>
<handler
class="org.springframework.tooling.boot.ls.commands.OpenResourceInEditor"
commandId="org.springframework.tooling.boot.ls.OpenResourceInEditor">
</handler>
<handler
class="org.springframework.tooling.boot.ls.commands.ToggleComment"
commandId="org.springframework.tooling.boot.ls.ToggleComment">
@@ -133,29 +125,6 @@
id="org.springframework.ide.eclipse.commands"
name="Spring Generic Text Editor">
</category>
<command
id="org.springframework.tooling.boot.ls.OpenJavaElement"
name="Open Java Element in Editor">
<commandParameter
id="bindingKey"
name="bindingKey"
optional="false">
</commandParameter>
<commandParameter
id="projectName"
name="projectName"
optional="false">
</commandParameter>
</command>
<command
id="org.springframework.tooling.boot.ls.OpenResourceInEditor"
name="Open File in Editor">
<commandParameter
id="path"
name="path"
optional="false">
</commandParameter>
</command>
<command
id="org.springframework.tooling.boot.ls.ToggleComment"
categoryId="org.springframework.ide.eclipse.commands"

View File

@@ -1,68 +0,0 @@
/*******************************************************************************
* Copyright (c) 2018 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.boot.ls.commands;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.ui.PartInitException;
import org.springframework.tooling.boot.ls.BootLanguageServerPlugin;
import org.springframework.tooling.ls.eclipse.commons.Utils;
/**
* Command for opening Java type given by its fully qualified name in an editor
*
* @author Alex Boyko
*
*/
public class OpenJavaElementInEditor extends AbstractHandler {
private static final String BINDING_KEY = "bindingKey";
private static final String PROJECT_NAME = "projectName";
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
String bindingKey = event.getParameter(BINDING_KEY);
String projectName = event.getParameter(PROJECT_NAME);
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if (project != null && bindingKey != null) {
IJavaProject javaProject = JavaCore.create(project);
if (javaProject != null) {
IJavaElement element = Utils.findElement(javaProject, bindingKey);
if (element == null) {
BootLanguageServerPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, BootLanguageServerPlugin.ID, "Cannot find element: " + bindingKey));
} else {
try {
JavaUI.openInEditor(element);
} catch (PartInitException | JavaModelException e) {
throw new ExecutionException("Error opening java element in editor", e);
}
}
} else {
BootLanguageServerPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, BootLanguageServerPlugin.ID, "Cannot find project: " + projectName));
}
}
return null;
}
}

View File

@@ -1,72 +0,0 @@
/*******************************************************************************
* Copyright (c) 2018 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.boot.ls.commands;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
/**
* Command for opening an editor given URI of the resource. (Platform command
* takes platform URI or path relative to the workspace)
*
* @author Alex Boyko
*
*/
public class OpenResourceInEditor extends AbstractHandler {
private static final String PATH = "path";
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IPath rootPath = root.getLocation();
IPath resourcePath = new Path(event.getParameter(PATH));
IResource resource = root.findMember(resourcePath.makeRelativeTo(rootPath));
if (resource == null && !(resource instanceof IFile)) {
throw new ExecutionException("cannot find file: " + event.getParameter(PATH)); //$NON-NLS-1$
}
final IWorkbenchWindow window = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow();
if (window == null) {
throw new ExecutionException("no active workbench window"); //$NON-NLS-1$
}
final IWorkbenchPage page = window.getActivePage();
if (page == null) {
throw new ExecutionException("no active workbench page"); //$NON-NLS-1$
}
try {
IDE.openEditor(page, (IFile) resource, true);
} catch (final PartInitException e) {
throw new ExecutionException("error opening file in editor", e); //$NON-NLS-1$
}
return null;
}
}