fix: more robust lsp startup

This commit is contained in:
FalsePattern 2024-05-11 15:01:17 +02:00
parent 993d28f4bf
commit b85496e55c
Signed by: falsepattern
GPG key ID: E930CDEC50C50E23
3 changed files with 23 additions and 3 deletions

View file

@ -18,6 +18,14 @@ Changelog structure reference:
## [Unreleased]
### Fixed
- LSP
- No more notification popup about zig env not being detected when not in a zig projects.
- Project
- ZLS should now be detected more reliably when creating new projects
## [14.0.1]
### Fixed

View file

@ -22,15 +22,17 @@ import lombok.val;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class ApplicationUtil {
private final static ExecutorService EXECUTOR_SERVICE;
private final static ScheduledExecutorService EXECUTOR_SERVICE;
static {
// Single threaded executor is used to simulate a behavior of async sequencial execution.
// All runnables are executed asyncly but they are executed in the order of their submission.
EXECUTOR_SERVICE = Executors.newSingleThreadExecutor();
EXECUTOR_SERVICE = Executors.newSingleThreadScheduledExecutor();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
@ -48,6 +50,10 @@ public class ApplicationUtil {
EXECUTOR_SERVICE.submit(runnable);
}
public static void pool(Runnable runnable, long delay, TimeUnit timeUnit) {
EXECUTOR_SERVICE.schedule(runnable, delay, timeUnit);
}
static public <T> T computableReadAction(Computable<T> computable) {
return ApplicationManager.getApplication().runReadAction(computable);
}

View file

@ -16,6 +16,7 @@
package com.falsepattern.zigbrains.zig.lsp;
import com.falsepattern.zigbrains.common.util.ApplicationUtil;
import com.falsepattern.zigbrains.common.util.StringUtil;
import com.falsepattern.zigbrains.lsp.IntellijLanguageClient;
import com.falsepattern.zigbrains.lsp.utils.FileUtils;
@ -40,6 +41,7 @@ import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
public class ZLSStartupActivity implements ProjectActivity {
@ -76,7 +78,8 @@ public class ZLSStartupActivity implements ProjectActivity {
val tmpFile = Files.createTempFile("zigbrains-zls-autoconf", ".json");
val config = ZLSConfigProvider.findEnvironment(project);
if (StringUtil.isEmpty(config.zig_exe_path()) && StringUtil.isEmpty(config.zig_lib_path())) {
Notifications.Bus.notify(new Notification("ZigBrains.ZLS", "(ZLS) Failed to detect zig path from project toolchain", NotificationType.WARNING));
// TODO this generates unnecessary noise in non-zig projects, find an alternative.
// Notifications.Bus.notify(new Notification("ZigBrains.ZLS", "(ZLS) Failed to detect zig path from project toolchain", NotificationType.WARNING));
configOK = false;
break blk;
}
@ -172,6 +175,9 @@ public class ZLSStartupActivity implements ProjectActivity {
if (zlsPath == null) {
//Project creation
ApplicationUtil.pool(() -> {
initZLS(project);
}, 5, TimeUnit.SECONDS);
return null;
}