moved resource listener registration to delegating stream provider to enable it for both cases
This commit is contained in:
@@ -14,7 +14,12 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.lsp4e.server.StreamConnectionProvider;
|
||||
|
||||
/**
|
||||
@@ -31,6 +36,7 @@ import org.eclipse.lsp4e.server.StreamConnectionProvider;
|
||||
public class DelegatingStreamConnectionProvider implements StreamConnectionProvider {
|
||||
|
||||
private StreamConnectionProvider provider;
|
||||
private ResourceListener fResourceListener;
|
||||
|
||||
public DelegatingStreamConnectionProvider() {
|
||||
String port = System.getProperty("boot-java-ls-port");
|
||||
@@ -45,6 +51,7 @@ public class DelegatingStreamConnectionProvider implements StreamConnectionProvi
|
||||
|
||||
@Override
|
||||
public Object getInitializationOptions(URI rootUri) {
|
||||
installResourceChangeListener(rootUri);
|
||||
return provider.getInitializationOptions(rootUri);
|
||||
}
|
||||
|
||||
@@ -66,6 +73,34 @@ public class DelegatingStreamConnectionProvider implements StreamConnectionProvi
|
||||
@Override
|
||||
public void stop() {
|
||||
this.provider.stop();
|
||||
if (fResourceListener != null) {
|
||||
ResourcesPlugin.getWorkspace().removeResourceChangeListener(fResourceListener);
|
||||
fResourceListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void installResourceChangeListener(URI rootPath) {
|
||||
if (rootPath == null || fResourceListener != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
IContainer[] containers = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(rootPath);
|
||||
if (containers.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (IContainer c : containers) {
|
||||
if (!(c instanceof IProject)) {
|
||||
continue;
|
||||
}
|
||||
IProject project = (IProject) c;
|
||||
fResourceListener = new ResourceListener("org.eclipse.languageserver.languages.springbootjava", project, Arrays.asList(
|
||||
FileSystems.getDefault().getPathMatcher("glob:**/pom.xml"),
|
||||
FileSystems.getDefault().getPathMatcher("glob:**/build.gradle")
|
||||
));
|
||||
project.getWorkspace().addResourceChangeListener(fResourceListener);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,17 +12,11 @@ package org.springframework.tooling.boot.java.ls;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
@@ -36,8 +30,6 @@ import org.osgi.framework.Bundle;
|
||||
@SuppressWarnings("restriction")
|
||||
public class SpringBootJavaLanguageServer extends ProcessStreamConnectionProvider {
|
||||
|
||||
private ResourceListener fResourceListener;
|
||||
|
||||
public SpringBootJavaLanguageServer() {
|
||||
List<String> commands = new ArrayList<>();
|
||||
commands.add(getJDKLocation());
|
||||
@@ -107,44 +99,4 @@ public class SpringBootJavaLanguageServer extends ProcessStreamConnectionProvide
|
||||
Files.copy(stream, dataFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
super.stop();
|
||||
if (fResourceListener != null) {
|
||||
ResourcesPlugin.getWorkspace().removeResourceChangeListener(fResourceListener);
|
||||
fResourceListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInitializationOptions(URI rootPath) {
|
||||
installResourceChangeListener(rootPath);
|
||||
return super.getInitializationOptions(rootPath);
|
||||
}
|
||||
|
||||
private void installResourceChangeListener(URI rootPath) {
|
||||
if (rootPath == null || fResourceListener != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
IContainer[] containers = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(rootPath);
|
||||
if (containers.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (IContainer c : containers) {
|
||||
if (!(c instanceof IProject)) {
|
||||
continue;
|
||||
}
|
||||
IProject project = (IProject) c;
|
||||
fResourceListener = new ResourceListener("org.eclipse.languageserver.languages.springbootjava", project, Arrays.asList(
|
||||
FileSystems.getDefault().getPathMatcher("glob:**/pom.xml"),
|
||||
FileSystems.getDefault().getPathMatcher("glob:**/build.gradle")
|
||||
));
|
||||
project.getWorkspace().addResourceChangeListener(fResourceListener);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user