Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support managing referenced libraries #213

Merged
merged 14 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions images/dark/icon-add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions images/dark/icon-remove.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions images/light/icon-add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions images/light/icon-remove.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions jdtls.ext/com.microsoft.jdtls.ext.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<plugin>
<extension point="org.eclipse.jdt.ls.core.delegateCommandHandler">
<delegateCommandHandler class="com.microsoft.jdtls.ext.core.CommandHandler">
<command id="java.project.refreshLib"/>
<command id="java.project.list"/>
<command id="java.getPackageData"/>
<command id="java.resolvePath" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public Object executeCommand(String commandId, List<Object> arguments, IProgress
if (!StringUtils.isBlank(commandId)) {
switch (commandId) {
case "java.project.list":
return ProjectCommand.execute(arguments, monitor);
return ProjectCommand.listProjects(arguments, monitor);
case "java.project.refreshLib":
return ProjectCommand.refreshLibraries(arguments, monitor);
case "java.getPackageData":
return PackageCommand.getChildren(arguments, monitor);
case "java.resolvePath":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jdt.ls.core.internal.JavaClientConnection;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.managers.UpdateClasspathJob;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
Expand All @@ -25,18 +31,30 @@ public class JdtlsExtActivator implements BundleActivator {

private static BundleContext context;

private static IJobChangeListener updateClasspathListener = new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (event.getJob() instanceof UpdateClasspathJob) {
JavaClientConnection connection = JavaLanguageServerPlugin.getInstance().getClientConnection();
connection.executeClientCommand("java.view.package.refresh", /* debounce = */true);
}
}
};

static BundleContext getContext() {
return context;
}

@Override
public void start(BundleContext bundleContext) throws Exception {
JdtlsExtActivator.context = bundleContext;
UpdateClasspathJob.getInstance().addJobChangeListener(JdtlsExtActivator.updateClasspathListener);
}

@Override
public void stop(BundleContext bundleContext) throws Exception {
JdtlsExtActivator.context = null;
UpdateClasspathJob.getInstance().removeJobChangeListener(JdtlsExtActivator.updateClasspathListener);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.eclipse.jdt.internal.core.JarEntryResource;
import org.eclipse.jdt.internal.core.JrtPackageFragmentRoot;
import org.eclipse.jdt.ls.core.internal.JDTUtils;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.lsp4j.jsonrpc.json.adapters.CollectionTypeAdapter;
import org.eclipse.lsp4j.jsonrpc.json.adapters.EnumTypeAdapter;

Expand Down Expand Up @@ -246,7 +247,7 @@ private static List<PackageNode> getContainers(PackageParams query, IProgressMon
.collect(Collectors.toList());
boolean isReferencedLibrariesExist = Arrays.stream(references)
.anyMatch(entry -> entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY || entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE);
if (isReferencedLibrariesExist) {
if (isReferencedLibrariesExist || !ProjectUtils.isVisibleProject(javaProject.getProject())) {
result.add(PackageNode.REFERENCED_LIBRARIES_CONTAINER);
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
import org.eclipse.jdt.ls.core.internal.managers.UpdateClasspathJob;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences.ReferencedLibraries;

import com.microsoft.jdtls.ext.core.model.NodeKind;
import com.microsoft.jdtls.ext.core.model.PackageNode;

public final class ProjectCommand {

public static List<PackageNode> execute(List<Object> arguments, IProgressMonitor monitor) {
public static List<PackageNode> listProjects(List<Object> arguments, IProgressMonitor monitor) {
String workspaceUri = (String) arguments.get(0);
IPath workspacePath = ResourceUtils.canonicalFilePathFromURI(workspaceUri);
String invisibleProjectName = getWorkspaceInvisibleProjectName(workspacePath);
Expand All @@ -47,6 +52,21 @@ public static List<PackageNode> execute(List<Object> arguments, IProgressMonitor
return children;
}

public static boolean refreshLibraries(List<Object> arguments, IProgressMonitor monitor) {
String workspaceUri = (String) arguments.get(0);
IPath workspacePath = ResourceUtils.canonicalFilePathFromURI(workspaceUri);
String projectName = ProjectUtils.getWorkspaceInvisibleProjectName(workspacePath);
IProject project = getWorkspaceRoot().getProject(projectName);
try {
ReferencedLibraries libraries = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getReferencedLibraries();
UpdateClasspathJob.getInstance().updateClasspath(JavaCore.create(project), libraries);
return true;
} catch (Exception e) {
JavaLanguageServerPlugin.logException("Exception occured during waiting for classpath to be updated", e);
return false;
}
}

private static IWorkspaceRoot getWorkspaceRoot() {
return ResourcesPlugin.getWorkspace().getRoot();
}
Expand Down
Loading