feat: Async command resolution
This commit is contained in:
parent
e68b89b6ed
commit
c8db133804
2 changed files with 31 additions and 3 deletions
|
@ -31,6 +31,6 @@ public class ZLSLanguageServerFactory implements LanguageServerFactory, Language
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setEnabled(boolean enabled, @NotNull Project project) {
|
public void setEnabled(boolean enabled, @NotNull Project project) {
|
||||||
this.enabled = enabled && ZLSStreamConnectionProvider.getCommand(project) != null;
|
this.enabled = enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,12 @@ import com.google.gson.Gson;
|
||||||
import com.intellij.notification.Notification;
|
import com.intellij.notification.Notification;
|
||||||
import com.intellij.notification.NotificationType;
|
import com.intellij.notification.NotificationType;
|
||||||
import com.intellij.notification.Notifications;
|
import com.intellij.notification.Notifications;
|
||||||
|
import com.intellij.openapi.application.ApplicationManager;
|
||||||
import com.intellij.openapi.diagnostic.Logger;
|
import com.intellij.openapi.diagnostic.Logger;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.project.ProjectUtil;
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import com.redhat.devtools.lsp4ij.server.ProcessStreamConnectionProvider;
|
import com.redhat.devtools.lsp4ij.server.ProcessStreamConnectionProvider;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
|
|
||||||
|
@ -19,14 +22,27 @@ import java.nio.file.InvalidPathException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
public class ZLSStreamConnectionProvider extends ProcessStreamConnectionProvider {
|
public class ZLSStreamConnectionProvider extends ProcessStreamConnectionProvider {
|
||||||
private static final Logger LOG = Logger.getInstance(ZLSStreamConnectionProvider.class);
|
private static final Logger LOG = Logger.getInstance(ZLSStreamConnectionProvider.class);
|
||||||
public ZLSStreamConnectionProvider(Project project) {
|
public ZLSStreamConnectionProvider(Project project) {
|
||||||
super(getCommand(project));
|
val command = getCommand(project);
|
||||||
|
val projectDir = ProjectUtil.guessProjectDir(project);
|
||||||
|
if (projectDir != null) {
|
||||||
|
setWorkingDirectory(projectDir.getPath());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
setCommands(command.get());
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getCommand(Project project) {
|
private static List<String> doGetCommand(Project project) {
|
||||||
var svc = ZLSProjectSettingsService.getInstance(project);
|
var svc = ZLSProjectSettingsService.getInstance(project);
|
||||||
val state = svc.getState();
|
val state = svc.getState();
|
||||||
var zlsPath = state.zlsPath;
|
var zlsPath = state.zlsPath;
|
||||||
|
@ -96,6 +112,18 @@ public class ZLSStreamConnectionProvider extends ProcessStreamConnectionProvider
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Future<List<String>> getCommand(Project project) {
|
||||||
|
val future = new CompletableFuture<List<String>>();
|
||||||
|
ApplicationManager.getApplication().executeOnPooledThread(() -> {
|
||||||
|
try {
|
||||||
|
future.complete(doGetCommand(project));
|
||||||
|
} catch (Throwable t) {
|
||||||
|
future.completeExceptionally(t);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean validatePath(String name, String pathTxt, boolean dir) {
|
private static boolean validatePath(String name, String pathTxt, boolean dir) {
|
||||||
if (pathTxt == null || pathTxt.isBlank()) {
|
if (pathTxt == null || pathTxt.isBlank()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue