fix: more robust lsp startup
This commit is contained in:
parent
993d28f4bf
commit
b85496e55c
3 changed files with 23 additions and 3 deletions
|
@ -18,6 +18,14 @@ Changelog structure reference:
|
||||||
|
|
||||||
## [Unreleased]
|
## [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]
|
## [14.0.1]
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -22,15 +22,17 @@ import lombok.val;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ApplicationUtil {
|
public class ApplicationUtil {
|
||||||
|
|
||||||
private final static ExecutorService EXECUTOR_SERVICE;
|
private final static ScheduledExecutorService EXECUTOR_SERVICE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Single threaded executor is used to simulate a behavior of async sequencial execution.
|
// 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.
|
// 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() {
|
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -48,6 +50,10 @@ public class ApplicationUtil {
|
||||||
EXECUTOR_SERVICE.submit(runnable);
|
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) {
|
static public <T> T computableReadAction(Computable<T> computable) {
|
||||||
return ApplicationManager.getApplication().runReadAction(computable);
|
return ApplicationManager.getApplication().runReadAction(computable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package com.falsepattern.zigbrains.zig.lsp;
|
package com.falsepattern.zigbrains.zig.lsp;
|
||||||
|
|
||||||
|
import com.falsepattern.zigbrains.common.util.ApplicationUtil;
|
||||||
import com.falsepattern.zigbrains.common.util.StringUtil;
|
import com.falsepattern.zigbrains.common.util.StringUtil;
|
||||||
import com.falsepattern.zigbrains.lsp.IntellijLanguageClient;
|
import com.falsepattern.zigbrains.lsp.IntellijLanguageClient;
|
||||||
import com.falsepattern.zigbrains.lsp.utils.FileUtils;
|
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.InvalidPathException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
public class ZLSStartupActivity implements ProjectActivity {
|
public class ZLSStartupActivity implements ProjectActivity {
|
||||||
|
@ -76,7 +78,8 @@ public class ZLSStartupActivity implements ProjectActivity {
|
||||||
val tmpFile = Files.createTempFile("zigbrains-zls-autoconf", ".json");
|
val tmpFile = Files.createTempFile("zigbrains-zls-autoconf", ".json");
|
||||||
val config = ZLSConfigProvider.findEnvironment(project);
|
val config = ZLSConfigProvider.findEnvironment(project);
|
||||||
if (StringUtil.isEmpty(config.zig_exe_path()) && StringUtil.isEmpty(config.zig_lib_path())) {
|
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;
|
configOK = false;
|
||||||
break blk;
|
break blk;
|
||||||
}
|
}
|
||||||
|
@ -172,6 +175,9 @@ public class ZLSStartupActivity implements ProjectActivity {
|
||||||
|
|
||||||
if (zlsPath == null) {
|
if (zlsPath == null) {
|
||||||
//Project creation
|
//Project creation
|
||||||
|
ApplicationUtil.pool(() -> {
|
||||||
|
initZLS(project);
|
||||||
|
}, 5, TimeUnit.SECONDS);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue